Minotaur 0.4.1
Docs for developers
TransSep.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
20#ifndef MINOTAURTRANSSEP_H
21#define MINOTAURTRANSSEP_H
22
23#include <stack>
24
25#include "Constraint.h"
26#include "Types.h"
27#include "NonlinearFunction.h"
28#include "OpCode.h"
29#include "CNode.h"
30
31namespace Minotaur {
32
33 class CGraph;
34 class CNode;
35 class LinearHandler;
36 class Problem;
37 typedef CGraph* CGraphPtr;
38 typedef std::deque<CNode *> CNodeQ;
39
40 class TransSep {
41 public:
42
44 TransSep();
45
51 TransSep(EnvPtr env, ProblemPtr problem);
52
54 ~TransSep();
55
60 //void checkCons(std::vector<ConstraintPtr> *sepCons);
61 void checkCons();
62
64 void createCG(std::vector<CGraphPtr> * cg, CNodeQ * dq, int *itnum,
65 CNode **tempN);
66
67 bool coeffValue(CNode * n2, double *cv,bool *n, CNode **n1,
68 std::vector<UInt > *idx);
69
70 void commonConsCheck(std::vector<double > *constCoeff);
72 void depthFS(int j, CNode *n1, std::vector<UInt > * m, int *itnum, CNodeQ *sNodes,
73 std::deque<int > *sOps, std::vector<CNode *> *sVars,
74 std::vector<CNode *> *sConsts);
75
76
77 //UInt eqnDirection(ConstraintPtr cptr);
79 bool explore(UInt *j, CNode *n1, std::vector<UInt > * m, int opc, int *itnum, UInt nvar, CNodeQ *sNodes,
80 std::deque<int > *sOps, std::vector<CNode *> *sVars,
81 std::vector<CNode *> *sConsts);
82
84 void finalCG(std::vector<CGraphPtr > * cg,
85 CNode **tempN,std::vector<double > *constCoeff, double *coeff,
86 std::vector<double > *hashVal1,double *x);
87
89 void sepDetection();
90 //void sepDetection(std::vector<ConstraintPtr> *sepCons);
91
93 UInt getNumVars() {return newVars_;}
94
97 void markVis(UInt i, int *itnum);
98
99 bool ifRepeated(CGraphPtr nlf,LinearFunctionPtr lfnew,
100 CGraphPtr cg,
101 double constCoeff, double coeff, LinearFunctionPtr lf);
102 void linearizeObj();
103
105 void mergeItrInfo(int mNum, CNodeQ *sNodes, std::deque<int > *sOps,
106 std::vector<CNode *> *sVars,
107 std::vector<CNode *> *sConsts);
108
110 int mergeItrNum(int j, int a, std::vector<UInt > * m);
111
112
113
114 bool sepPartsSearch(UInt sp, std::vector<CGraphPtr > *nlfnew,
115 std::vector<LinearFunctionPtr > *lfnew,
116 CGraphPtr cg, double constCoeff,
117 LinearFunctionPtr lf, std::vector<UInt > *nsp,
118 double coeff);
119
121 bool rootChildren(const CNode * o, std::stack<CNode *> *candNodes,
122 std::stack<int > *candOp,
123 double *coeff, UInt nnode, UInt nvar, double *ub,
124 //double *lb, LinearFunctionPtr lf);
126
128 std::vector<CGraphPtr> sepPartsCGraph(CNodeQ * dq, UInt nnode,
129 std::vector<double > *constCoeff, double *coeff,
130 std::vector<double > *hashVal1, double *x);
135 bool sepCheck(double coeff, std::stack<CNode *> *candNodes,
136 std::stack<int > *candOp, UInt nnode, UInt nvar,
137 //double *ub, double *lb, LinearFunctionPtr lf);
138 double *ub, LinearFunctionPtr lf);
139
140
142 void tempPopulate(CNode *n1, std::stack<CNode *> * tempNodes);
143
145
146 void updateVisNodeItr(UInt* j, std::vector<UInt >*m, CNode *n1,
147 int opc, int idx, CNodeQ *sNodes,
148 std::deque<int > *sOps,
149 std::vector<CNode *> *sVars,
150 std::vector<CNode *> *sConsts);
152 void writeProb();
153
154 private:
156 EnvPtr env_;
157
159 LoggerPtr logger_;
160
161 // For log:
162 static const std::string me_;
163
164 // Problem whose constraints are to be checked for separability detection.
165 ProblemPtr problem_;
166
167 // No. of new variable added to the origina problem after sep detection
168 UInt newVars_;
169
170 // Separable parts
171 std::vector<CNodeQ > sepNodes_;
172
173 // Name of the Constraint that are separable
174
175 // Opcodes of nodes in separable parts
176 std::vector< std::deque< int> > sepOps_;
177
178 // Variables in separable parts
179 std::vector< std::vector< CNode *> > sepVars_;
180
181 // Constant nodes in separable parts
182 std::vector< std::vector< CNode *> > sepConst_;
183
184 std::vector<ConstraintPtr> sepCons_;
185
186 double intTol_;
187 };
188 typedef TransSep* TransSepPtr;
189 typedef const TransSep* ConstTransSepPtr;
190}
191
192#endif // MINOTAURTRANSSEP_H
193
Declare class CNode to represent node of a computational graph of a nonlinear function.
Get information about a constraint in a given Problem.
Declare abstract base class NonlinearFunction.
Declare the OpCodes used in Minotaur.
Declare important 'types' used in Minotaur.
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
Definition: Problem.h:74
Definition: TransSep.h:40
void createCG(std::vector< CGraphPtr > *cg, CNodeQ *dq, int *itnum, CNode **tempN)
Generate computation graph.
Definition: TransSep.cpp:402
~TransSep()
Destroy.
Definition: TransSep.cpp:58
void depthFS(int j, CNode *n1, std::vector< UInt > *m, int *itnum, CNodeQ *sNodes, std::deque< int > *sOps, std::vector< CNode * > *sVars, std::vector< CNode * > *sConsts)
Perform Depth first search rooted at node n1 at iteration number j.
Definition: TransSep.cpp:474
bool explore(UInt *j, CNode *n1, std::vector< UInt > *m, int opc, int *itnum, UInt nvar, CNodeQ *sNodes, std::deque< int > *sOps, std::vector< CNode * > *sVars, std::vector< CNode * > *sConsts)
Explore further from node n1 at iteration number j.
Definition: TransSep.cpp:554
std::vector< CGraphPtr > sepPartsCGraph(CNodeQ *dq, UInt nnode, std::vector< double > *constCoeff, double *coeff, std::vector< double > *hashVal1, double *x)
Generate computational graph of separable parts.
Definition: TransSep.cpp:1092
void finalCG(std::vector< CGraphPtr > *cg, CNode **tempN, std::vector< double > *constCoeff, double *coeff, std::vector< double > *hashVal1, double *x)
Generate final computation graph.
Definition: TransSep.cpp:702
UInt getNumVars()
Return no. of vars added.
Definition: TransSep.h:93
int mergeItrNum(int j, int a, std::vector< UInt > *m)
Find iteration to merge the current iteration to.
Definition: TransSep.cpp:926
void writeProb()
Write reformulated problem after separability detection.
Definition: TransSep.cpp:1359
bool sepCheck(double coeff, std::stack< CNode * > *candNodes, std::stack< int > *candOp, UInt nnode, UInt nvar, double *ub, LinearFunctionPtr lf)
Definition: TransSep.cpp:1142
void updateVisNodeItr(UInt *j, std::vector< UInt > *m, CNode *n1, int opc, int idx, CNodeQ *sNodes, std::deque< int > *sOps, std::vector< CNode * > *sVars, std::vector< CNode * > *sConsts)
Add information of the node already visited.
Definition: TransSep.cpp:1344
void sepDetection()
Find separability of given problem.
Definition: TransSep.cpp:790
void checkCons()
Definition: TransSep.cpp:85
TransSep()
Default constructor.
Definition: TransSep.cpp:40
void tempPopulate(CNode *n1, std::stack< CNode * > *tempNodes)
Populate initial list for depth first search rooted at node n1.
Definition: TransSep.cpp:1290
bool rootChildren(const CNode *o, std::stack< CNode * > *candNodes, std::stack< int > *candOp, double *coeff, UInt nnode, UInt nvar, double *ub, LinearFunctionPtr lf)
Check whether constraint is separable.
Definition: TransSep.cpp:983
void markVis(UInt i, int *itnum)
Definition: TransSep.cpp:814
void mergeItrInfo(int mNum, CNodeQ *sNodes, std::deque< int > *sOps, std::vector< CNode * > *sVars, std::vector< CNode * > *sConsts)
Merge current iteration with iteration mNum.
Definition: TransSep.cpp:895
Definition: ActiveNodeStore.h:20
unsigned int UInt
Unsigned integer.
Definition: Types.h:30

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025