Encapsulates all the instance level information for a CPLEX model, namely the CPLEX object, the relative ASL and all the locals of the driver up to the moment in which optimize would be called.
It can not be created any other way than by reading an nl file, and any assignment moves actual ownership. At the end of its life, it deletes the relative structures.
Public Functions
-
inline virtual Status::SolStatus getStatus()
Get the solution status P(generic)
-
inline virtual int getNumVars()
Get the number of variables.
-
inline virtual int getNumCons()
Get the number of constraints.
-
inline virtual double getObj()
Get the current objective value.
-
inline virtual int getSolution(int first, int length, double *sol)
Get “length” variables of the current problem in an array, starting at the specified position.
- Parameters
first – Index of the first variable to return
length – Number of variables to return
sol – Array to store the values
-
inline virtual std::string error(int code)
Get the error message corresponding to the code.
-
inline XPRSprob getXPRSprob()
Get a pointer to the underlying XPRESSprob object.
-
inline virtual void optimize()
Solve the problem.
-
inline int getIntAttr(int what)
Get an integer attribute identified by XPRESS native enum.
-
inline double getDoubleAttr(int what)
Get a double attribute identified by XPRESS native enum.
-
inline bool isMIP()
Return true if the problem is MIP.
-
inline void setParam(int XPRSParam, int value)
Set an integer XPRESS control parameter.
-
inline void setParam(int XPRSParam, double value)
Set a double XPRESS control parameter.
-
inline int getIntParam(int XPRSParam)
Get an integer XPRESS control parameter.
-
inline double getDoubleParam(int XPRSParam)
Get a double XPRESS control parameter.
-
inline virtual void enableLazyConstraints()
Enable adding lazy constraints via callbacks (to be called only once), call before calling AMPLModel::optimize() if planning to add lazy constraints via callbacks.
-
inline virtual void setAMPLParameter(SolverParams::SolverParameters param, int value)
Set an integer parameter using ampls aliases.
-
inline virtual void setAMPLParameter(SolverParams::SolverParameters param, double value)
Set a double parameter using ampls aliases.
-
inline virtual int getAMPLIntParameter(SolverParams::SolverParameters params)
Get an integer parameter using ampls aliases.
-
inline virtual double getAMPLDoubleParameter(SolverParams::SolverParameters params)
Get a double parameter using ampls aliases.
-
inline virtual int getAMPLIntAttribute(SolverAttributes::Attribs attrib)
Get an integer attribute using ampls aliases.
-
inline virtual double getAMPLDoubleAttribute(SolverAttributes::Attribs attrib)
Get a double attribute using ampls aliases.
-
inline virtual std::vector<Option> getOptions()
Get a list of the options supported by the solver, as seen from the -= output of the solver driver.
Note that these options are the ones found in the list of the corresponding solver driver options at: https://dev.ampl.com/solvers/index.html
- Returns
A vector of option descriptions
-
virtual void setOption(const char *name, int value)
Set a solver driver option to the specified value.
See getOptions() for a list of supported options.
-
virtual void setOption(const char *name, double value)
Set an option to the specified value.
See getOptions() for a list of supported options.
-
virtual void setOption(const char *name, const char *value)
Set an option to the specified value. See getOptions() for a list of supported options.
-
inline virtual int getIntOption(const char *name)
Get the current value of the option ‘name’.
See getOptions() for a list of supported options.
-
inline virtual double getDoubleOption(const char *name)
Get the current value of the option ‘name’.
See getOptions() for a list of supported options.
-
inline virtual std::string getStringOption(const char *name)
Get the current value of the option ‘name’. See getOptions() for a list of supported options.
-
inline virtual void refresh()
Refresh the underlying model (especially useful if modifying with setOption() functionalities that need suffixes to be read from the NL file
-
inline std::string getFileName()
Get the name of the NL file from which the model has been loaded from.
-
std::map<int, std::string> getVarMapInverse()
Get the map from variable index in the solver interface to AMPL variable instance name.
-
std::map<int, std::string> getConMapInverse()
Get the map from constraint index in the solver interface to AMPL variable instance name.
-
inline std::map<std::string, int> getVarMap()
Get the map from variable name to index in the solver interface.
-
inline std::map<std::string, int> getConMap()
Get the map from constraint name to index in the solver interface.
-
std::map<std::string, int> getVarMapFiltered(const char *beginWith)
Return the variable map filtered by the variable name, to avoid getting the whole (possibly large) map.
- Parameters
beginWith – Prefix to be matched
-
std::map<std::string, int> getConMapFiltered(const char *beginWith)
Return the constraint map filtered by the constraint name, to avoid getting the whole (possibly large) map.
- Parameters
beginWith – Prefix to be matched
-
inline virtual int setCallback(GenericCallback *callback)
Set a generic callback to be called during optimization.
This function is automatically dispatched when (and only when) assigning an ampls::GenericCallback, as it needs a special treatment to automatically create the solver-specific wrapper
- Parameters
callback – The generic callback to be set
-
inline int setCallback(impl::BaseCallback *callback)
Set callback to be called during optimization.
- Parameters
callback – The callback to be set
-
std::vector<double> getSolutionVector()
Get all the variables of the current problem.
-
inline std::vector<double> getDualVector()
Get all the dual values of the current problem.
-
inline virtual void writeSol()
Write the solution file to the defualt location (filename.sol in the original directory)
-
inline virtual void writeSol(const char *solFileName)
Write the solution file to a specific file.
- Parameters
solFileName – Path of the solution file to write
-
void printModelVars(bool onlyNonZero)
Utility function: prints all variables to screen.
Public Static Functions
-
template<class T>
static inline T load(const char *nlfile, const char **options = nullptr)
Load a model from an NL file
- Template Parameters
T – Concrete class (e.g. CPLEXModel, GurobiModel, …) to create
- Parameters
-
- Returns
-