53 for (
auto&& op : opts) {
54 if (op.first ==
"verbose") {
58 ss <<
"Unknown option \"" << op.first <<
"\"" << std::endl;
59 throw CasadiException(ss.str());
64 if (verbose_) casadi_message(
"Reading file \"" +
filename +
"\"");
67 const casadi_int header_sz = 10;
68 std::vector<std::string> header(header_sz);
69 for (casadi_int k=0; k<header_sz; ++k) {
70 getline(s_, header[k]);
74 if (header.at(0).at(0)==
'g') {
76 }
else if (header.at(0).at(0)==
'b') {
79 casadi_error(
"File could not be read");
83 std::stringstream ss(header[1]);
84 ss >> n_var_ >> n_con_ >> n_obj_ >> n_eq_ >> n_lcon_;
86 casadi_message(
"n_var=" +
str(n_var_) +
", n_con =" +
str(n_con_) +
", "
87 "n_obj=" +
str(n_obj_) +
", n_eq=" +
str(n_eq_) +
", "
88 "n_lcon=" +
str(n_lcon_));
92 std::stringstream ss4(header[4]);
93 ss4 >> nlvc_ >> nlvo_ >> nlvb_;
95 casadi_message(
"nlvc=" +
str(nlvc_) +
", nlvo=" +
str(nlvo_) +
", nlvb=" +
str(nlvb_));
99 std::stringstream ss6(header[6]);
100 ss6 >> nbv_ >> niv_ >> nlvbi_ >> nlvci_ >> nlvoi_;
102 casadi_message(
"nbv=" +
str(nbv_) +
", niv =" +
str(niv_) +
", "
103 "nlvbi=" +
str(nlvbi_) +
", nlvci=" +
str(nlvci_) +
", "
104 "nlvoi=" +
str(nlvoi_));
108 nlp_.
x =
MX::sym(
"x", 1, 1, n_var_);
112 nlp_.
g.resize(n_con_, 0);
115 nlp_.
x_lb.resize(n_var_, -
inf);
117 nlp_.
x_init.resize(n_var_, 0);
120 nlp_.
g_lb.resize(n_con_, -
inf);
129 for (casadi_int j=0; j<nlvb_-nlvbi_; ++j) nlp_.
discrete.push_back(
false);
132 for (casadi_int j=0; j<nlvbi_; ++j) nlp_.
discrete.push_back(
true);
135 for (casadi_int j=0; j<nlvc_ - (nlvb_ + nlvci_); ++j) nlp_.
discrete.push_back(
false);
138 for (casadi_int j=0; j<nlvci_; ++j) nlp_.
discrete.push_back(
true);
141 for (casadi_int j=0; j<nlvo_ - (nlvc_ + nlvoi_); ++j) nlp_.
discrete.push_back(
false);
144 for (casadi_int j=0; j < nlvoi_; ++j) nlp_.
discrete.push_back(
true);
147 casadi_int max_nlvc_nlvo = (nlvc_ < nlvo_) ? nlvo_ : nlvc_;
148 for (casadi_int j=0; j<n_var_-(max_nlvc_nlvo+niv_+nbv_); ++j) nlp_.
discrete.push_back(
false);
151 for (casadi_int j = 0; j<nbv_; ++j) nlp_.
discrete.push_back(
true);
154 for (casadi_int j = 0; j<niv_; ++j) nlp_.
discrete.push_back(
true);
156 casadi_assert(nlp_.
discrete.size()==n_var_,
157 "Number of variables in the header don't match");
163 std::streampos offset = s_.tellg();
165 s_.open(
filename.c_str(), std::ifstream::binary);
173 nlp_.
f = sign_*nlp_.
f;
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)