Minotaur 0.4.1
Docs for developers
Loading...
Searching...
No Matches
RecipHandler.h
Go to the documentation of this file.
1
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2010 - 2025 The Minotaur Team.
5//
6
14#ifndef MINOTAURRECIPHANDLER_H
15#define MINOTAURRECIPHANDLER_H
16
17#include "Handler.h"
18#include "Types.h"
19
20namespace Minotaur {
21
22 class LinearFunction;
23 typedef LinearFunction *LinearFunctionPtr;
24
25 class RecipHandler : public Handler {
26 public:
27 RecipHandler(EnvPtr env, ProblemPtr problem);
29
35 ConstVariablePtr ovar, char sense = 'E');
36
37 // base class method -- not used here
38 void addConstraint(ConstraintPtr) override { assert(0); }
39
40 void relaxInitFull(RelaxationPtr, SolutionPool *, bool *) override {}
41 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf) override;
42 void relaxNodeFull(NodePtr, RelaxationPtr, bool *) override {}
43 void relaxNodeInc(NodePtr node, RelaxationPtr rel,
44 bool *isInfeasible) override;
45
46 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
47 bool &should_prune, double &inf_meas) override;
48
50 CutManager *cutman, SolutionPoolPtr s_pool,
51 ModVector &p_mods, ModVector &r_mods, bool *sol_found,
52 SeparationStatus *status) override;
53
54 void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x,
55 ModVector &mods, BrVarCandSet &cands,
56 BrCandVector &gencands, bool &is_inf) override;
57
58 ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x,
59 RelaxationPtr rel, BranchDirection dir) override;
60
61 Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel,
62 SolutionPoolPtr s_pool) override;
63
64 SolveStatus presolve(PreModQ *pre_mods, bool *changed,
65 Solution **sol) override;
66
68 ModVector &p_mods, ModVector &r_mods) override;
69
70 std::string getName() const override;
71 void writeStats(std::ostream &out) const override;
72
73 private:
74 struct RecipCons {
75 ConstraintPtr con;
78 VariablePtr riv;
79 VariablePtr rov;
80 char sense;
81 ConstraintPtr secCon;
82 ConstraintVector linCons;
83
84 RecipCons(ConstraintPtr newcon, ConstVariablePtr ivar,
85 ConstVariablePtr ovar, char s)
86 : con(newcon), iv(ivar), ov(ovar), riv(0), rov(0), sense(s),
87 secCon(0), linCons(3)
88 {
89 }
90 };
91
92 typedef RecipCons *RecipConsPtr;
93 typedef std::vector<RecipConsPtr> RecipConsVec;
94 typedef RecipConsVec::iterator RecipConsIter;
95
96 struct SepaStats {
97 int iters;
98 int tangentcuts;
99 };
100
101 struct RecipPresolveStats {
102 UInt iters;
103 UInt vBnd;
104 RecipPresolveStats() : iters(0), vBnd(0) {}
105 };
106
107 RecipConsVec consd_;
108 static const std::string me_;
109 RecipPresolveStats pStats_;
110 SepaStats sStats_;
111 double eTol_;
112 double vTol_;
113 ProblemPtr p_;
114 LoggerPtr log_;
115
116 // Tangent cut at the current point (if violated)
117 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
118 RelaxationPtr rel, bool &ifcuts);
119
120 // Tangent of y = 1/x at x0 (x0 = 0: free placeholder row). Creates the
121 // row if 'row' is null, otherwise overwrites it.
122 ConstraintPtr addTangent_(VariablePtr x, VariablePtr y, double x0,
123 RelaxationPtr rel, ConstraintPtr row);
124
125 // Three tangent rows over the current bounds of x
126 void addLin_(RecipCons &cd, RelaxationPtr rel);
127
128 // Chord row over the current bounds of x
129 void addSecant_(RecipCons &cd, RelaxationPtr rel);
130
131 // Branching point for x (relaxation variable)
132 double getBrPoint_(VariablePtr v, double xval) const;
133
134 // Violation of y = 1/x at the given solution vector
135 double getViol_(const RecipCons &cd, const DoubleVector &x) const;
136
137 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
138 bool &should_prune, double &inf_meas);
139
140 // Build/refresh the rows of one constraint. Returns true if the node
141 // is infeasible.
142 bool relaxRecip_(RecipCons &cd, RelaxationPtr rel, bool init);
143
144 // Bounds on y from bounds on x and vice versa. Returns true if infeasible.
145 bool propRecipBnds_(RecipConsPtr cd, bool *changed);
146
147 int updatePBnds_(VariablePtr p, double newlb, double newub,
148 bool *changed);
149
150 bool varBndsFromCons_(bool *changed);
151 };
152
153} // namespace Minotaur
154#endif // MINOTAURRECIPHANDLER_H
Define abstract base class for handlers of various kinds.
Declare important 'types' used in Minotaur.
Base class for describing candidates for branching on a node in branch-and-bound.
Definition BrCand.h:32
The Constraint class is used to manage a constraint.
Definition Constraint.h:61
Abstract base class to manage cuts in the relaxation.
Definition CutManager.h:42
Definition Environment.h:28
Base class for handling specific types of constraints or objective.
Definition Handler.h:49
Definition Modification.h:29
Definition Node.h:54
Definition Problem.h:74
Definition RecipHandler.h:25
bool presolveNode(RelaxationPtr p, NodePtr node, SolutionPoolPtr s_pool, ModVector &p_mods, ModVector &r_mods) override
Presolve the problem and its relaxation at a node.
Definition RecipHandler.cpp:490
std::string getName() const override
Return the name of the handler.
Definition RecipHandler.cpp:496
void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar, ConstVariablePtr ovar, char sense='E')
Definition RecipHandler.cpp:78
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir) override
Get the modifcation that creates a given (up or down) branch.
Definition RecipHandler.cpp:356
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool) override
Return branches for branching.
Definition RecipHandler.cpp:370
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *) override
Create root relaxation if doing full node relaxations.
Definition RecipHandler.h:40
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf) override
find branching candidates.
Definition RecipHandler.cpp:305
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas) override
Check if a solution is feasible.
Definition RecipHandler.cpp:234
void relaxNodeFull(NodePtr, RelaxationPtr, bool *) override
Create a relaxation for a node, building from scratch.
Definition RecipHandler.h:42
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol) override
Initial presolve.
Definition RecipHandler.cpp:480
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible) override
Create an incremental relaxation for a node.
Definition RecipHandler.cpp:197
void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel, CutManager *cutman, SolutionPoolPtr s_pool, ModVector &p_mods, ModVector &r_mods, bool *sol_found, SeparationStatus *status) override
add cuts to separate a given point.
Definition RecipHandler.cpp:271
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf) override
Create root relaxation if doing incremental node relaxations.
Definition RecipHandler.cpp:185
void addConstraint(ConstraintPtr) override
Add constraint to be handled by this handler.
Definition RecipHandler.h:38
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition RecipHandler.cpp:501
Definition Relaxation.h:53
Definition SolutionPool.h:28
Definition Solution.h:30
Definition Variable.h:31
Definition AbsHandler.h:19
BranchDirection
Two directions for branching.
Definition Types.h:201
unsigned int UInt
Unsigned integer.
Definition Types.h:30
SeparationStatus
Status from separation routine:
Definition Types.h:217
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition Types.h:158

Minotaur source code documented by Doxygen 1.9.8 on Thu Nov 19 2026