52 std::istream& s = *s_ptr_;
55 for (
auto&& op : opts) {
56 if (op.first ==
"verbose") {
60 ss <<
"Unknown option \"" << op.first <<
"\"" << std::endl;
61 throw CasadiException(ss.str());
65 if (verbose_) casadi_message(
"Reading file \"" +
filename +
"\"");
68 const casadi_int header_sz = 10;
69 std::vector<std::string> header(header_sz);
70 for (casadi_int k=0; k<header_sz; ++k) {
71 getline(s, header[k]);
75 if (header.at(0).at(0)==
'g') {
77 }
else if (header.at(0).at(0)==
'b') {
80 casadi_error(
"File could not be read");
84 std::stringstream ss(header[1]);
85 ss >> n_var_ >> n_con_ >> n_obj_ >> n_eq_ >> n_lcon_;
87 casadi_message(
"n_var=" +
str(n_var_) +
", n_con =" +
str(n_con_) +
", "
88 "n_obj=" +
str(n_obj_) +
", n_eq=" +
str(n_eq_) +
", "
89 "n_lcon=" +
str(n_lcon_));
93 std::stringstream ss4(header[4]);
94 ss4 >> nlvc_ >> nlvo_ >> nlvb_;
96 casadi_message(
"nlvc=" +
str(nlvc_) +
", nlvo=" +
str(nlvo_) +
", nlvb=" +
str(nlvb_));
100 std::stringstream ss6(header[6]);
101 ss6 >> nbv_ >> niv_ >> nlvbi_ >> nlvci_ >> nlvoi_;
103 casadi_message(
"nbv=" +
str(nbv_) +
", niv =" +
str(niv_) +
", "
104 "nlvbi=" +
str(nlvbi_) +
", nlvci=" +
str(nlvci_) +
", "
105 "nlvoi=" +
str(nlvoi_));
109 nlp_.
x =
MX::sym(
"x", 1, 1, n_var_);
113 nlp_.
g.resize(n_con_, 0);
116 nlp_.
x_lb.resize(n_var_, -
inf);
118 nlp_.
x_init.resize(n_var_, 0);
121 nlp_.
g_lb.resize(n_con_, -
inf);
130 for (casadi_int j=0; j<nlvb_-nlvbi_; ++j) nlp_.
discrete.push_back(
false);
133 for (casadi_int j=0; j<nlvbi_; ++j) nlp_.
discrete.push_back(
true);
136 for (casadi_int j=0; j<nlvc_ - (nlvb_ + nlvci_); ++j) nlp_.
discrete.push_back(
false);
139 for (casadi_int j=0; j<nlvci_; ++j) nlp_.
discrete.push_back(
true);
142 for (casadi_int j=0; j<nlvo_ - (nlvc_ + nlvoi_); ++j) nlp_.
discrete.push_back(
false);
145 for (casadi_int j=0; j < nlvoi_; ++j) nlp_.
discrete.push_back(
true);
148 casadi_int max_nlvc_nlvo = (nlvc_ < nlvo_) ? nlvo_ : nlvc_;
149 for (casadi_int j=0; j<n_var_-(max_nlvc_nlvo+niv_+nbv_); ++j) nlp_.
discrete.push_back(
false);
152 for (casadi_int j = 0; j<nbv_; ++j) nlp_.
discrete.push_back(
true);
155 for (casadi_int j = 0; j<niv_; ++j) nlp_.
discrete.push_back(
true);
157 casadi_assert(nlp_.
discrete.size()==n_var_,
158 "Number of variables in the header don't match");
164 std::streampos offset = s.tellg();
167 s_ptr_->seekg(offset);
174 nlp_.
f = sign_*nlp_.
f;
static std::unique_ptr< std::istream > ifstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::in, bool fail=true)
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
std::vector< double > x_lb
Bounds on x.
std::vector< double > g_ub
Variables.
std::vector< bool > discrete
Discrete variables.
std::vector< double > lambda_init
Dual initial guess.
std::vector< double > x_ub
Variables.
std::vector< MX > x
Variables.
std::vector< double > g_lb
Bounds on g.
std::vector< MX > g
Constraints.
std::vector< double > x_init
Primal initial guess.
std::string str(const T &v)
String representation, any type.
std::string filename(const std::string &path)