diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-11-21 02:10:41 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-11-21 02:10:41 +1100 |
commit | f7f83793c2d3f8f37b49bf1eab04f08f8118797e (patch) | |
tree | 8598f1c2fcca83515e50bf3e7a055c7bf1ed08a8 /impl | |
parent | 50f2130f18e86055892c870c14af5101feb568ff (diff) |
Bug fixes for stupid things.
Diffstat (limited to 'impl')
-rw-r--r-- | impl/Operator.hpp | 42 | ||||
-rw-r--r-- | impl/VariableAssignment.hpp | 22 |
2 files changed, 24 insertions, 40 deletions
diff --git a/impl/Operator.hpp b/impl/Operator.hpp index 0b08866..d16152e 100644 --- a/impl/Operator.hpp +++ b/impl/Operator.hpp @@ -171,14 +171,20 @@ struct MinCostFlow : public Operator<Domain> { _solver.ChgCost(i, costs[i].template as<MCFClass::CNumber>()); } _solver.SolveMCF(); - if (_solver.MCFGetStatus() == MCFClass::kUnfeasible){ + + if (_solver.MCFGetStatus() != MCFClass::kOK) { return -infinity<Domain>(); - } else if (_solver.MCFGetFO() == MCFClass::Inf<MCFClass::FONumber>()) { - return infinity<Domain>(); - } else if (_solver.MCFGetFO() == -MCFClass::Inf<MCFClass::FONumber>()) { - return -infinity<Domain>(); } else { - return _solver.MCFGetFO(); + MCFClass::FONumber num = _solver.MCFGetFO(); + if (num == MCFClass::Inf<MCFClass::FONumber>()) { + return infinity<Domain>(); + } else if (num == -MCFClass::Inf<MCFClass::FONumber>()) { + return -infinity<Domain>(); + } else { + if (((int)num) == -2147483648) + return -infinity<Domain>(); + return num; + } } } void print(std::ostream& cout) const { @@ -217,30 +223,6 @@ private: mutable MCFSimplex _solver; }; -/*#include "TemplateConstraintMatrix.hpp" - -template<typename Domain> -struct MinimumCostFlow : public Operator<Domain> { - MinimumCostFlow() { - } - Domain solve(const Domain& d) const { - - } - virtual Domain eval(const std::vector<Domain>& arguments) const { - if (arguments.size() != 1) - throw "Incorrect number of arguments."; - return solve(arguments[0]); - } - void print(std::ostream& cout) const { - cout << "minCostFlow"; - } -private: - TemplateConstraintMatrix& constraint; // T - std::vector<Domain> guard; // c - std::vector<std::vector<Domain>> multiplication; //A - unsigned int row; -};*/ - template<typename T> std::ostream& operator<<(std::ostream& cout, const Operator<T>& op) { op.print(cout); diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp index 08002b8..67896ef 100644 --- a/impl/VariableAssignment.hpp +++ b/impl/VariableAssignment.hpp @@ -60,15 +60,17 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> { IdSet<Variable<Domain> > get_changed() { IdSet<Variable<Domain> > changed; - for (typename IdSet<Variable<Domain> >::iterator - it = _touched.begin(), - ei = _touched.end(); - it != ei; - ++it) { - Variable<Domain>& var = _system.variable(*it); - if (!_unstable.contains(var) && _old_values[var] != _values[var]) { - changed.insert(var); - _touched.remove(var); + if (_touched.size() > 0) { + for (typename IdSet<Variable<Domain> >::iterator + it = _touched.begin(), + ei = _touched.end(); + it != ei; + ++it) { + Variable<Domain>& var = _system.variable(*it); + if (!_unstable.contains(var) && _old_values[var] != _values[var]) { + changed.insert(var); + _touched.remove(var); + } } } //_touched.clear(); @@ -88,7 +90,6 @@ private: const DynamicMaxStrategy<Domain>& const_strat = _strategy; DependencyAssignment assignment(*this, x); Domain val = _system[x]->eval(assignment, const_strat); - stack_depth--; if (val != _values[x]) { log::fixpoint << x << " = " << val << std::endl; @@ -108,6 +109,7 @@ private: log::fixpoint << indent() << x << " did not change: " << x << " = " << val << std::endl; } + stack_depth--; } else { log::fixpoint << indent() << x << " is stable: " << x << " = " << _values[x] << std::endl; |