Minotaur 0.4.1
Docs for developers
FixVarsHeur.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
15#ifndef MINOTAURFIXVARSHEUR_H
16#define MINOTAURFIXVARSHEUR_H
17
18#include "Heuristic.h"
19#include "Types.h"
20
21namespace Minotaur
22{
23class Problem;
28 UInt numSol; // Number of solutions found
29 UInt numPresolve; // Number of times presolve was done
30 double time; // Time taken in this heuristic
31};
32
33class FixVarsHeur : public Heuristic
34{
35public:
38
41
43 void createHandlers();
44
47
49 void setHandlers(HandlerVector& handlers);
50
52 void writeStats(std::ostream& out) const;
53
54private:
55 // A map of constraints with the number of unfixed variables in the constratint
56 std::map<ConstraintPtr, UInt> consNumVar_;
57
58 // Down lock for each variable
59 UIntVector downLock_;
60
61 // Environment
62 EnvPtr env_;
63
64 // Handlers for the problem
65 HandlerVector handlers_;
66
67 // Check with lock number done?
68 bool lock_;
69
70 // For printing messages
71 static const std::string me_;
72
73 // Multiplier for binary variables to create a priority
74 UInt mbin_;
75
76 // Multiplier for nonlinear variables to create a priority
77 UInt mnl_;
78
79 // Variable fixing mods done
80 ModVector mods_;
81
82 // Problem
83 ProblemPtr p_;
84
85 // Statistics
86 FixVarsHeurStats* stats_;
87
88 // Up lock for each variable
89 UIntVector upLock_;
90
91 // Compute lock number of each variable
92 void computeLocks_();
93
94 // fix the variable v
95 void fix_(VariablePtr v);
96
97 // fix the variable v based on its lock number
98 void fixByLock_(VariablePtr v);
99
100 // Fix Variables
101 void FixVars_(std::map<VariablePtr, UInt>& unfixedVars);
102
103 // Update the solution in solution pool if found
104 void foundNewSol_(SolutionPoolPtr s_pool, bool& restart);
105
106 // initialize the correct data structures for heuristic
107 void initialize_();
108
109 // Check whether x is feasible
110 bool isFeasible_(const double* x);
111
112 // Compares two elements in a map
113 static bool mapCompare_(const std::pair<VariablePtr, UInt>& p1,
114 const std::pair<VariablePtr, UInt>& p2);
115
116 // presolve here.
117 bool presolve_(SolutionPoolPtr s_pool,
118 std::map<VariablePtr, UInt>& unfixedVars);
119
120 // gets the best variable to fix
121 VariablePtr selectVarToFix_(std::map<VariablePtr, UInt>& unfixedVars);
122
123 // Unfix fixed variables.
124 void unfixVars_();
125
126 // update itmp of each variable in the constraint if it is covered right from start
127 void updateItmp_(ConstraintPtr c);
128
129 // update Map of each variable in the constraint once it is covered
130 void updateMap_(ConstraintPtr c, std::map<VariablePtr, UInt>& unfixedVars);
131};
132
134} // namespace Minotaur
135#endif
136
Define abstract base class for heuristics of various kinds.
Declare important 'types' used in Minotaur.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
Definition: Environment.h:28
Definition: FixVarsHeur.h:34
FixVarsHeur(EnvPtr env, ProblemPtr p)
default constructor
Definition: FixVarsHeur.cpp:38
~FixVarsHeur()
default destructor
Definition: FixVarsHeur.cpp:52
void writeStats(std::ostream &out) const
writing the statistics to the logger
Definition: FixVarsHeur.cpp:527
void createHandlers()
create handlers for the problem
Definition: FixVarsHeur.cpp:501
void setHandlers(HandlerVector &handlers)
set handlers of the problem
Definition: FixVarsHeur.cpp:496
void solve(NodePtr, RelaxationPtr, SolutionPoolPtr s_pool)
call to heuristic
Definition: FixVarsHeur.cpp:58
Definition: Heuristic.h:30
Definition: Node.h:54
Definition: Problem.h:74
Definition: Relaxation.h:53
Definition: SolutionPool.h:28
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
A statistic struct for trivial heuristic.
Definition: FixVarsHeur.h:27

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