CONOPT
Loading...
Searching...
No Matches
modeldata.h
Go to the documentation of this file.
1/*****************************************************************************/
2/* File: modeldata.h */
3/* Version 4.27 */
4/* CONOPT header file to be used internally in CONOPT defining the calling */
5/* conventions used inside the CONOPT library / DLL / shared object. */
6/* */
7/* Copyright (C) 1995-2024 GAMS Software GmbH */
8/* Copyright (C) 1995-2024 GAMS Development Corporation */
9/* All Rights Reserved. */
10/* */
11/* THIS MATERIAL IS CONSIDERED A TRADE SECRET. */
12/* UNAUTHORIZED ACCESS, USE, REPRODUCTION OR DISTRIBUTION IS PROHIBITED. */
13/*****************************************************************************/
18
19#ifndef _MODELDATA_H_
20#define _MODELDATA_H_
21
22#include <algorithm>
23#include <vector>
24
25#include "defines.h"
26
27#ifdef _MSC_VER
28#pragma warning( push )
29// disable warning on using STL (members without a DLL interface) in ConoptModelData (class with a DLL interface)
30#pragma warning( disable: 1744 )
31#endif
32
43{
44 ConoptVariable(int idx, double low, double up, double cur = 0, int varstat = -1)
45 : index(idx),
46 lower(low),
47 upper(up),
48 curr(cur),
49 varstatus(varstat)
50 {
51 consindex_.clear();
52 value_.clear();
53 nlflag_.clear();
54
55 sortorder_.clear();
56 }
57
62 void addNonzero(int conindex, double value, int nlflag)
63 {
64 sortorder_.push_back(consindex_.size());
65
66 consindex_.push_back(conindex);
67 value_.push_back(value);
68 nlflag_.push_back(nlflag);
69
70 }
71
77 {
78 std::sort(sortorder_.begin(), sortorder_.end(),
79 [&](int a, int b){
80 return consindex_[a] < consindex_[b];
81 });
82 }
83
84 int index;
85 double lower;
86 double upper;
87 double curr;
89
90 /* matrix information */
91 std::vector<int> consindex_;
92 std::vector<double> value_;
93 std::vector<int> nlflag_;
94
95 /* information required to sort the non-zeros by consindex */
96 std::vector<int> sortorder_;
97};
98
99
110{
111 ConoptConstraint(int idx, ConoptConstraintType type, double bound, int slackstat)
112 : index(idx),
113 constype(type),
114 rhs(bound),
115 slackstatus(slackstat)
116 {
117 }
118
119 int index;
121 double rhs;
123};
124
125
129class COI_API ConoptModelData {
130public:
135
140
169 virtual int readMatrix(double lower[], double curr[], double upper[], int vsta[], int type[], double rhs[],
170 int esta[], int colsta[], int rowno[], double value[], int nlflag[], int numvar, int numcon, int numnz);
171
181 unsigned int numvar,
182 unsigned int numcons,
183 unsigned int numnz,
184 unsigned int numnlnz
185 );
186
193 ConoptConstraintType constype,
194 double rhs,
195 int slackstatus = -1
196 );
197
204 ConoptConstraintType constype,
205 double rhs,
206 const std::vector<int>& varindex,
207 const std::vector<double>& value,
208 const std::vector<int>& nlflag,
209 int slackstatus = -1
210 );
211
218 double lower,
219 double upper,
220 double curr = 0,
221 int varstatus = -1
222 );
223
230 double lower,
231 double upper,
232 const std::vector<int>& consindex,
233 const std::vector<double>& value,
234 const std::vector<int>& nlflag,
235 double curr = 0,
236 int varstatus = -1
237 );
238
245
252
282 void setInitialStatusOption(int inistat);
283
289 int numVar() const;
290
296 int numCons() const;
297
304
310 const ConoptVariable& getVariable(int index) const;
311
317 const ConoptConstraint& getConstraint(int index) const;
318
325
332 const std::vector<int>& rownum,
333 const std::vector<int>& colnum
334 );
335
337 const std::vector<int>& getSDLagrangianRowNumbers() const;
338
340 const std::vector<int>& getSDLagrangianColumnNumbers() const;
341
342 /* callback methods for function and derivative evaluations */
343
355 virtual int FDEval(const double x[], double* g, double jac[], int rowno, const int jacnum[], int mode, int ignerr,
356 int* errcnt, int numvar, int numjac, int thread)
357 {
358 return 0;
359 }
360
361 /* The optional callback routines for first derivative evaluations */
362
375 virtual int FDEvalIni(const double x[], const int rowlist[], int mode, int listsize, int numthread, int ignerr,
376 int* errcnt, int numvar)
377 {
378 return 0;
379 }
380
391 virtual int FDEvalEnd(int ignerr, int* errcnt)
392 {
393 return 0;
394 }
395
406 virtual int FDInterval(const double xmin[], const double xmax[], double* gmin, double* gmax, double jmin[],
407 double jamx[], int rowno, const int jacnum[], int mode, double pinf, int numvar, int numjac)
408 {
409 return 0;
410 }
411
412 /* The optional callback routines for the second derivative evaulations */
413
414#if 0 // not sure whether this is needed to C and C++.
417 virtual int SDLagrSize(int* nodrv, int numvar, int numcon, int* nhess, int maxhess)
418 {
419 return 0;
420 }
421#endif
422
432 virtual int SDLagrVal(const double x[], const double u[], const int hsrw[], const int hscl[], double hsvl[],
433 int* nodrv, int numvar, int numcon, int nhess)
434 {
435 return 0;
436 }
437
445 virtual int SDDirLagr(const double x[], const double dx[], const double u[], double d2g[], int newpt, int* nodrv,
446 int numvar, int numcon)
447 {
448 return 0;
449 }
450
458 virtual int SDDir(const double x[], const double dx[], double d2g[], int rowno, const int jacnum[], int* nodrv,
459 int numvar, int numjac, int thread)
460 {
461 return 0;
462 }
463
473 virtual int SDDirIni(const double x[], const double dx[], const int rowlist[], int listsize, int numthread,
474 int newpt, int* nodrv, int numvar)
475 {
476 return 0;
477 }
478
488 virtual int SDDirEnd(int* nodrv)
489 {
490 return 0;
491 }
492
493
494
495 friend class ConoptCpp;
496
497private:
498
499 /* clears the model data */
500 void clear()
501 {
502 variables_.clear();
503 constraints_.clear();
504
505 hessrownum_.clear();
506 hesscolnum_.clear();
507
508 numvar_ = 0;
509 numcons_ = 0;
510 numnz_ = 0;
511 numnlnz_ = 0;
512 numhessnz_ = -1;
513 optsense_ = (int)(ConoptSense::Minimize);
514 objectivecon_ = -1;
515 objectivevar_ = -1;
516
517 inistat_ = 0;
518 }
519
520 unsigned int numvar_;
521 unsigned int numcons_;
522 unsigned int numnz_;
523 unsigned int numnlnz_;
524 int numhessnz_;
525 int optsense_;
526 int objectivecon_;
527 int objectivevar_;
528
529 int inistat_;
530
531 bool probdimset_;
532 ConoptSDEvaluationType sdevaltype_;
533
534 std::vector<ConoptVariable> variables_;
535 std::vector<ConoptConstraint> constraints_;
536
537 std::vector<int> hessrownum_;
538 std::vector<int> hesscolnum_;
539};
540
541#ifdef _MSC_VER
542#pragma warning( pop )
543#endif
544
545#endif // _MODELDATA_H_
const std::vector< int > & getSDLagrangianColumnNumbers() const
returns the column numbers in the second derivative of the lagrangian structure
friend class ConoptCpp
Definition modeldata.h:495
const std::vector< int > & getSDLagrangianRowNumbers() const
returns the row numbers in the second derivative of the lagrangian structure
virtual ~ConoptModelData()
ConoptObjectiveElement
the element that is used for the objective function
Definition defines.h:46
int addVariable(double lower, double upper, double curr=0, int varstatus=-1)
adds a variable to the model. The non-zero coefficients are added later.
int addVariable(double lower, double upper, const std::vector< int > &consindex, const std::vector< double > &value, const std::vector< int > &nlflag, double curr=0, int varstatus=-1)
adds a variable to the problem. The matrix non-zeros are added based on the supplied constraints.
ConoptSense
the objective sense
Definition defines.h:57
void setObjectiveElement(ConoptObjectiveElement elem, int elemindex)
sets the index for the objective variable or constraint
int addConstraint(ConoptConstraintType constype, double rhs, int slackstatus=-1)
adds a constraint to the problem. The non-zero coefficients are added later
ConoptConstraintType
the constraint type
Definition defines.h:28
int addConstraint(ConoptConstraintType constype, double rhs, const std::vector< int > &varindex, const std::vector< double > &value, const std::vector< int > &nlflag, int slackstatus=-1)
adds a constraint to the problem. The matrix non-zeros are added based on the supplied variables
void setOptimizationSense(ConoptSense sense)
sets the optimisation direction.
virtual int readMatrix(double lower[], double curr[], double upper[], int vsta[], int type[], double rhs[], int esta[], int colsta[], int rowno[], double value[], int nlflag[], int numvar, int numcon, int numnz)
loads the structure of the model into CONOPT.
void setProblemDimension(unsigned int numvar, unsigned int numcons, unsigned int numnz, unsigned int numnlnz)
sets the problem dimension. This is called if the user wants to implement a custom readMatrix() metho...
void setInitialStatusOption(int inistat)
the setting to indicate how the initial status of the variables and slack variables will be handled.
void setSDLagrangianStructure(const std::vector< int > &rownum, const std::vector< int > &colnum)
sets the structure of the second derivatives of the Lagrangian
void setSDEvaluationType(ConoptSDEvaluationType sdevaltype)
informs CONOPT of the method for evaluating the second derivative
ConoptSDEvaluationType
the evaluation type for the directional second derivatives
Definition defines.h:86
virtual int SDDirLagr(const double x[], const double dx[], const double u[], double d2g[], int newpt, int *nodrv, int numvar, int numcon)
computes the directional second derivative for the Lagrangian
Definition modeldata.h:445
virtual int SDDir(const double x[], const double dx[], double d2g[], int rowno, const int jacnum[], int *nodrv, int numvar, int numjac, int thread)
computes the directional second derivative for a single constraint
Definition modeldata.h:458
virtual int SDDirIni(const double x[], const double dx[], const int rowlist[], int listsize, int numthread, int newpt, int *nodrv, int numvar)
called by CONOPT before a sequence of 2DDir calls each time either the point or the direction changes...
Definition modeldata.h:473
virtual int SDDirEnd(int *nodrv)
called by CONOPT after a sequence of 2DDir calls each time either the point or the direction changes.
Definition modeldata.h:488
virtual int SDLagrVal(const double x[], const double u[], const int hsrw[], const int hscl[], double hsvl[], int *nodrv, int numvar, int numcon, int nhess)
Computes and returns the numerical values of the Hessian.
Definition modeldata.h:432
virtual int FDEval(const double x[], double *g, double jac[], int rowno, const int jacnum[], int mode, int ignerr, int *errcnt, int numvar, int numjac, int thread)
defines the nonlinearities of the model by returning numerical values.
Definition modeldata.h:355
virtual int FDEvalEnd(int ignerr, int *errcnt)
an optional function that will be called at the end of the function evaluation stage.
Definition modeldata.h:391
virtual int FDEvalIni(const double x[], const int rowlist[], int mode, int listsize, int numthread, int ignerr, int *errcnt, int numvar)
an optional function that can be used to improve the efficiency of the function evaulations.
Definition modeldata.h:375
virtual int FDInterval(const double xmin[], const double xmax[], double *gmin, double *gmax, double jmin[], double jamx[], int rowno, const int jacnum[], int mode, double pinf, int numvar, int numjac)
defines intervals for the nonlinearities of the model, again by returning numerical values.
Definition modeldata.h:406
int numCons() const
returns the number of constraints in the model
int numVar() const
returns the number of variables in the model
int numHessianNonzeros() const
returns the number of non-zeros in the Hessian
const ConoptConstraint & getConstraint(int index) const
returns a reference to the constraint object
const ConoptVariable & getVariable(int index) const
returns a reference to the variable object
the constraint data
Definition modeldata.h:110
ConoptConstraintType constype
Definition modeldata.h:120
ConoptConstraint(int idx, ConoptConstraintType type, double bound, int slackstat)
Definition modeldata.h:111
the variable data
Definition modeldata.h:43
std::vector< int > sortorder_
Definition modeldata.h:96
void addNonzero(int conindex, double value, int nlflag)
adds a non-zero to the variable data
Definition modeldata.h:62
std::vector< int > consindex_
Definition modeldata.h:91
void sortNonzeros()
sorts the non-zeros by constraint index.
Definition modeldata.h:76
ConoptVariable(int idx, double low, double up, double cur=0, int varstat=-1)
Definition modeldata.h:44
std::vector< int > nlflag_
Definition modeldata.h:93
std::vector< double > value_
Definition modeldata.h:92