Minotaur 0.4.1
Docs for developers
AMPLInterface.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2008 - 2025 The Minotaur Team.
5//
6
13#ifndef MINOTAURAMPLINTERFACE_H
14#define MINOTAURAMPLINTERFACE_H
15
16#include "Types.h"
17
18//#include "nlp.h"
19//#undef filename
20
21struct expr;
22typedef double efunc(expr*);
23struct ASL;
24
25namespace Minotaur {
26class CGraph;
27class CNode;
28class Environment;
29class LinearFunction;
30class PolynomialFunction;
31class Problem;
32class QuadraticFunction;
33class Solution;
34typedef CGraph* CGraphPtr;
35typedef Environment* EnvironmentPtr;
36typedef LinearFunction* LinearFunctionPtr;
37typedef PolynomialFunction* PolyFunPtr;
38typedef QuadraticFunction* QuadraticFunctionPtr;
39typedef const Solution* ConstSolutionPtr;
40}
41
42namespace MINOTAUR_AMPL {
43
44class AMPLNonlinearFunction;
45typedef AMPLNonlinearFunction* AMPLNlfPtr;
46
48typedef enum {
49 FReader,
58} ReaderType;
59
60
61class AMPLInterface;
62typedef AMPLInterface * AMPLInterfacePtr;
63
64
65// ------------------------------------------------------------------------ //
66// ------------------------------------------------------------------------ //
67
75public:
77 AMPLInterface(Minotaur::EnvPtr env, std::string solver="minotaurampl");
78
81
83 void freeASL();
84
86 ASL * getAsl();
87
89 const double * getInitialPoint() const;
90
93
96
98 Minotaur::ProblemPtr readInstance(std::string fname);
99
102 Minotaur::SolveStatus status);
103
104 void writeProblem(std::ostream &out) const;
105private:
107 Minotaur::EnvPtr env_;
108
113 std::map <efunc*, int> functionMap_;
114
116 const double intTol_;
117
119 Minotaur::LoggerPtr logger_;
120
122 static const std::string me_;
123
125 ASL *myAsl_;
126
128 int nCons_;
129
139 int nDefVars_;
140
142 int nDefVarsBco_;
143
145 int nDefVarsCo1_;
146
151 int nVars_;
152
154 ReaderType readerType_;
155
157 std::vector<Minotaur::VariablePtr> vars_;
158
160 const double zTol_;
161
163 void addDefinedVars_(Minotaur::ProblemPtr instance);
164
166 void addLinearConstraint_(int i, Minotaur::ProblemPtr problemPtr);
167
169 void addLinearObjective_(int i, Minotaur::ProblemPtr problemPtr);
170
175 void addLinearTermsFromConstr_(Minotaur::LinearFunctionPtr &lf, int i);
176
181 void addLinearTermsFromObj_(Minotaur::LinearFunctionPtr &lf, int i);
182
184 void addOptions_();
185
187 void addQuadraticConstraint_(int i, Minotaur::ProblemPtr problemPtr);
188
189 void addQuadraticDefCons_(Minotaur::ProblemPtr instance);
190 void addQuadraticDefCons2_(Minotaur::ProblemPtr instance);
191
193 void addQuadraticObjective_(int i, Minotaur::ProblemPtr problemPtr);
194
196 void addVariablesFromASL_(Minotaur::ProblemPtr problemPtr);
197
199 void addSOS_(Minotaur::ProblemPtr instance);
200
206 Minotaur::ProblemPtr copyInstanceFromASL_();
207 Minotaur::ProblemPtr copyInstanceFromASL2_();
208
223 void createFunctionMap_();
224
226 Minotaur::ProblemType findProblemType_();
227
229 void findVars_(expr *e_ptr, std::set<int> & vars);
230
231
233 Minotaur::CNode* getCGraph_(expr *e_ptr, Minotaur::CGraphPtr cgraph,
234 Minotaur::ProblemPtr instance);
235
237 Minotaur::FunctionType getConstraintsType_();
238
240 Minotaur::FunctionType getConstraintType_(int i);
241
246 Minotaur::FunctionType getDef1ConstraintType_(int i);
247
249 Minotaur::FunctionType getDefConstraintType_(int i);
250
256 Minotaur::FunctionType getExpressionType_(expr *e_ptr);
257
262 Minotaur::ProblemPtr getInstanceFromASL_(
263 std::vector<std::set<int> > &vids);
269 Minotaur::FunctionType getMultExpressionType_(expr *e_ptr);
270
272 Minotaur::FunctionType getObjFunctionType_(Minotaur::UInt obj_index=0);
273
280 void getOptionsFromEnv_(std::string pre);
281
287 Minotaur::FunctionType getPMExpressionType_(expr *e_ptr);
288
289 void getPoly_(Minotaur::LinearFunctionPtr & lfPtr,
291 Minotaur::PolyFunPtr & pfPtr,
292 double & c, expr *e_ptr);
293
299 Minotaur::FunctionType getPow1ExpressionType_(expr *e_ptr);
300
306 Minotaur::FunctionType getSumlistExpressionType_(expr *e_ptr);
307
309 void readFile_(std::string *fname, ReaderType readerType);
310
311 Minotaur::ProblemPtr readInstanceASL_(std::string fname);
312 Minotaur::ProblemPtr readInstanceCG_(std::string fname);
313
314 void saveNlVars_(std::vector<std::set<int> > &vars);
315
320 void unsupportedOp_(int opcode);
321
327 void writeExpression_(expr *e_ptr, std::ostream &out) const;
328
336 void writeExpression_(int i, bool is_obj, std::ostream &out) const;
337
345 void writeLin_(Minotaur::UInt i, bool is_obj, std::ostream &out) const;
346};
347
348} // namespace MINOTAUR_AMPL
349
350#endif
351
ReaderType
What kind of ASL reader is used to read the .nl file.
Definition: AMPLInterface.h:48
@ PFGHReader
First derivatives and partially separable structure.
Definition: AMPLInterface.h:55
@ PFGReader
Definition: AMPLInterface.h:54
@ FGReader
No derivatives, linear objective and constraints only.
Definition: AMPLInterface.h:50
@ FGHReader
Definition: AMPLInterface.h:52
Declare important 'types' used in Minotaur.
Interface to read ampl models using AMPL Solver Library. AMPLInterface class provides methods to read...
Definition: AMPLInterface.h:74
Minotaur::ProblemPtr readInstance(std::string fname)
Read an instance from a .nl file 'fname'.
Definition: AMPLInterface.cpp:2029
AMPLInterface(Minotaur::EnvPtr env, std::string solver="minotaurampl")
Constructor.
Definition: AMPLInterface.cpp:67
const double * getInitialPoint() const
Get the initial point provided in the .nl file.
Definition: AMPLInterface.cpp:1299
ASL * getAsl()
Get pointer to the ASL structure myAsl_.
Definition: AMPLInterface.cpp:926
void freeASL()
Free the ASL data structure myAsl_;.
Definition: AMPLInterface.cpp:914
~AMPLInterface()
Destroy.
Definition: AMPLInterface.cpp:88
Minotaur::UInt getNumDefs() const
Get the number of defined variables.
Definition: AMPLInterface.cpp:1470
void writeSolution(Minotaur::ConstSolutionPtr sol, Minotaur::SolveStatus status)
Write the solution to the AMPL acceptable .sol file.
Definition: AMPLInterface.cpp:2609
ReaderType getReaderType()
What kind of reader from ASL was used to read the .nl file.
Definition: AMPLInterface.cpp:1920
Definition: CGraph.h:33
CNode denotes a node in the computational graph. It stores the op-code, children, parents and other a...
Definition: CNode.h:48
Definition: Environment.h:28
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: Logger.h:37
PolynomialFunction represents functions of the form , where is a MonomialFunction.
Definition: PolynomialFunction.h:160
Definition: Problem.h:74
Definition: QuadraticFunction.h:38
Definition: Solution.h:30
Definition: ActiveNodeStore.h:20
ProblemType
The different classes of problems.
Definition: Types.h:44
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
FunctionType
Different types of functions in Minotaur.
Definition: Types.h:65
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition: Types.h:158

Minotaur source code documented by Doxygen 1.9.4 on Fri Apr 25 2025