19 using namespace Couenne;
26 std::ofstream
f (fname.c_str ());
28 f << std::setprecision (10);
34 f <<
"* MINLP Written by Couenne (https://projects.coin-or.org/Couenne)" << std::endl
36 <<
"* " <<
nVars () <<
" variables, " <<
nCons () <<
" constraints" << std::endl << std::endl;
42 for (
int i=0,
j=0; i <
nVars (); i++)
43 if (
Var (i) -> Multiplicity () > 0) {
46 if (!(++
j % nline))
f << std::endl <<
" ";
59 f <<
",objvar;" << std::endl << std::endl;
62 have_positive =
false,
67 for (
int i=0; i <
nVars (); i++)
68 if ((
Var (i) -> Multiplicity () > 0) &&
78 for (
int i=0; i <
nVars (); i++)
79 if ((
Var (i) -> Multiplicity () > 0) &&
89 for (
int i=0; i <
nVars (); i++)
90 if ((
Var (i) -> Multiplicity () > 0) &&
102 f <<
" positive variables ";
105 for (
int i=0,
j=0; i <
nVars (); i++)
106 if ((
Var (i) -> Multiplicity () > 0) &&
112 if (!(++
j % nline))
f << std::endl <<
" ";
121 f <<
';' << std::endl << std::endl;
127 f <<
" binary variables ";
129 for (
int i=0,
j=0; i <
nVars (); i++)
130 if ((
Var (i) -> Multiplicity () > 0) &&
136 if (!(++
j % nline))
f << std::endl <<
" ";
140 f <<
';' << std::endl << std::endl;
146 f <<
" integer variables ";
148 for (
int i=0,
j=0; i <
nVars (); i++)
149 if ((
Var (i) -> Multiplicity () > 0) &&
155 if (!(++
j % nline))
f << std::endl <<
" ";
159 f <<
';' << std::endl << std::endl;
168 for (; i <
nCons (); i++) {
171 if (!(++
j % nline))
f << std::endl <<
" ";
176 for (; i <
nVars (); i++)
177 if ((
Var (i) -> Type () ==
AUX) &&
178 (
Var (i) -> Multiplicity () > 0)) {
181 if (!(++
j % nline))
f << std::endl <<
" ";
186 if (!no_eqns)
f <<
',';
187 f <<
"objdef;" << std::endl << std::endl;
193 for (; i <
nCons (); i++) {
195 f <<
'e' << ++
j <<
".. ";
198 lb = (*(
Con (i) ->
Lb ())) (),
199 ub = (*(
Con (i) ->
Ub ())) ();
215 f <<
';' << std::endl << std::endl;
218 for (; i <
nVars (); i++)
219 if ((
Var (i) -> Type () ==
AUX) &&
220 (
Var (i) -> Multiplicity () > 0)) {
222 f <<
'e' << ++
j <<
".. ";
227 f <<
" =E= 0;" << std::endl << std::endl;
230 f <<
"objdef.. - objvar + ";
232 f <<
" =E= 0;" << std::endl << std::endl;
236 for (
int i=0; i <
nVars (); i++)
237 if (
Var (i) -> Multiplicity () > 0) {
240 f <<
".l = " <<
X (i) <<
';' << std::endl;
244 f <<
".lo = " <<
Lb (i) <<
';' << std::endl;
249 f <<
".up = " <<
Ub (i) <<
';' << std::endl;
255 f <<
"Model m / all /;" << std::endl
256 <<
"m.limrow=0; m.limcol=0;" << std::endl
257 <<
"Solve m using MINLP minimizing objvar;" << std::endl;
int nVars() const
Total number of variables.
std::string problemName_
problem name
void print(std::ostream &=std::cout)
Display current representation of problem: objective, linear and nonlinear constraints, and auxiliary variables.
void fint fint fint real fint real real real real * f
void writeGAMS(const std::string &fname)
Write nonlinear problem to a .gms file.
CouenneConstraint * Con(int i) const
i-th constraint
exprVar * Var(int i) const
Return pointer to i-th variable.
CouNumber * Ub() const
Return vector of upper bounds.
double CouNumber
main number type in Couenne
CouNumber * X() const
Return vector of variables.
int nCons() const
Get number of constraints.
CouenneObjective * Obj(int i) const
i-th objective
CouNumber * Lb() const
Return vector of lower bounds.
bool isInteger(CouNumber x)
is this number integer?