@@ -41,7 +41,7 @@ namespace linspire
4141 utils::inf_rational solver::ub (const utils::var x) const noexcept { return vars[x].get_ub (); }
4242 utils::inf_rational solver::val (const utils::var x) const noexcept { return vars[x].val ; }
4343
44- bool solver::new_eq (const utils::lin &lhs, const utils::lin &rhs, const std::optional<std::reference_wrapper< constraint>> & reason) noexcept
44+ bool solver::new_eq (const utils::lin &lhs, const utils::lin &rhs, constraint * reason) noexcept
4545 {
4646 LOG_TRACE (utils::to_string (lhs) + " == " + utils::to_string (rhs));
4747 utils::lin expr = lhs - rhs;
@@ -79,7 +79,7 @@ namespace linspire
7979 }
8080 }
8181
82- bool solver::new_lt (const utils::lin &lhs, const utils::lin &rhs, bool strict, const std::optional<std::reference_wrapper< constraint>> & reason) noexcept
82+ bool solver::new_lt (const utils::lin &lhs, const utils::lin &rhs, bool strict, constraint * reason) noexcept
8383 {
8484 LOG_TRACE (utils::to_string (lhs) + (strict ? " < " : " <= " ) + utils::to_string (rhs));
8585 utils::lin expr = lhs - rhs;
@@ -152,12 +152,12 @@ namespace linspire
152152 for (const auto &[v, c] : l.vars )
153153 if (is_positive (c)) // we use the most restrictive upper bound of v
154154 for (const auto &w : vars.at (v).ubs .begin ()->second )
155- cnfl.push_back (* w);
155+ cnfl.push_back (w);
156156 else if (is_negative (c)) // we use the most restrictive lower bound of v
157157 for (const auto &w : vars.at (v).lbs .rbegin ()->second )
158- cnfl.push_back (* w);
158+ cnfl.push_back (w);
159159 for (const auto &w : vars.at (x_i).lbs .rbegin ()->second ) // we use the most restrictive lower bound of x_i
160- cnfl.push_back (* w);
160+ cnfl.push_back (w);
161161 return false ;
162162 }
163163 }
@@ -173,12 +173,12 @@ namespace linspire
173173 for (const auto &[v, c] : l.vars )
174174 if (is_positive (c)) // we use the most restrictive lower bound of v
175175 for (const auto &w : vars.at (v).lbs .rbegin ()->second )
176- cnfl.push_back (* w);
176+ cnfl.push_back (w);
177177 else if (is_negative (c)) // we use the most restrictive upper bound of v
178178 for (const auto &w : vars.at (v).ubs .begin ()->second )
179- cnfl.push_back (* w);
179+ cnfl.push_back (w);
180180 for (const auto &w : vars.at (x_i).ubs .begin ()->second ) // we use the most restrictive upper bound of x_i
181- cnfl.push_back (* w);
181+ cnfl.push_back (w);
182182 return false ;
183183 }
184184 }
@@ -187,7 +187,7 @@ namespace linspire
187187
188188 bool solver::match (const utils::lin &l0, const utils::lin &l1) const noexcept { return lb (l0) <= ub (l1) && ub (l0) >= lb (l1); }
189189
190- bool solver::set_lb (const utils::var x, const utils::inf_rational &v, const std::optional<std::reference_wrapper< constraint>> & reason) noexcept
190+ bool solver::set_lb (const utils::var x, const utils::inf_rational &v, constraint * reason) noexcept
191191 {
192192 assert (x < vars.size ());
193193 assert (v > utils::rational::negative_infinite);
@@ -196,30 +196,30 @@ namespace linspire
196196 { // inconsistent bound..
197197 cnfl.clear ();
198198 if (reason)
199- cnfl.push_back (reason. value () );
199+ cnfl.push_back (reason);
200200 for (const auto &w : vars.at (x).ubs .begin ()->second ) // we use the most restrictive upper bound of x
201- cnfl.push_back (* w);
201+ cnfl.push_back (w);
202202 return false ;
203203 }
204204 if (reason)
205205 { // we have a reason for this bound..
206- if (auto it = reason->get (). lbs .find (x); it != reason->get (). lbs .end ())
206+ if (auto it = reason->lbs .find (x); it != reason->lbs .end ())
207207 { // we already have a lower bound for this variable in the reason..
208208 if (it->second < v)
209209 { // we update the lower bound only if the new one is more restrictive..
210- vars.at (x).unset_lb (it->second , reason-> get () );
210+ vars.at (x).unset_lb (it->second , * reason);
211211 it->second = v;
212212 }
213213 }
214214 else
215- reason->get (). lbs .emplace (x, v);
215+ reason->lbs .emplace (x, v);
216216 }
217217 vars.at (x).set_lb (v, reason);
218218 if (val (x) < v && !is_basic (x))
219219 update (x, v);
220220 return true ;
221221 }
222- bool solver::set_ub (const utils::var x, const utils::inf_rational &v, const std::optional<std::reference_wrapper< constraint>> & reason) noexcept
222+ bool solver::set_ub (const utils::var x, const utils::inf_rational &v, constraint * reason) noexcept
223223 {
224224 assert (x < vars.size ());
225225 assert (v < utils::rational::positive_infinite);
@@ -228,23 +228,23 @@ namespace linspire
228228 { // inconsistent bound..
229229 cnfl.clear ();
230230 if (reason)
231- cnfl.push_back (reason. value () );
231+ cnfl.push_back (reason);
232232 for (const auto &w : vars.at (x).lbs .rbegin ()->second ) // we use the most restrictive lower bound of x
233- cnfl.push_back (* w);
233+ cnfl.push_back (w);
234234 return false ;
235235 }
236236 if (reason)
237237 { // we have a reason for this bound..
238- if (auto it = reason->get (). ubs .find (x); it != reason->get (). ubs .end ())
238+ if (auto it = reason->ubs .find (x); it != reason->ubs .end ())
239239 { // we already have an upper bound for this variable in the reason..
240240 if (it->second > v)
241241 { // we update the upper bound only if the new one is more restrictive..
242- vars.at (x).unset_ub (it->second , reason-> get () );
242+ vars.at (x).unset_ub (it->second , * reason);
243243 it->second = v;
244244 }
245245 }
246246 else
247- reason->get (). ubs .emplace (x, v);
247+ reason->ubs .emplace (x, v);
248248 }
249249 vars.at (x).set_ub (v, reason);
250250 if (val (x) > v && !is_basic (x))
0 commit comments