3 #include <boost/foreach.hpp> 17 "Attempt to find a variable, means you have a pointer on it, which means it has been added through a function, which means it should have been registered..." 28 ,_problemVariable(
"SolverVariable")
43 if (_memory.capacity() > 0)
67 os <<
"Solver status:" << std::endl;
68 os <<
"\tSize: " <<
n() << std::endl;
73 static const std::string info =
"Abstract solver";
79 if (std::find(_objectives.begin(), _objectives.end(), &objective) != _objectives.end())
81 std::cout <<
"[ocra::Solver::internalAddObjective] Objective was already added in the solver, so it cannot be added again\n" <<
"\tObjective is named: " << objective.getName() << std::endl;
86 _objectives.push_back(&objective);
87 _problemVariable.
insert(&const_cast<GenericObjective*>(&objective)->getVariable());
93 if (std::find(_constraints.begin(), _constraints.end(), &constraint) != _constraints.end())
95 std::cout <<
"[ocra::Solver::internalAddConstraint] Constraint was already added in the solver, so it cannot be added again\n" <<
"\tConstraint is named: " << constraint.getName() << std::endl;
101 _constraints.push_back(&constraint);
102 _problemVariable.
insert(&const_cast<GenericConstraint*>(&constraint)->getVariable());
108 std::vector<const GenericObjective*>::iterator it = std::find(_objectives.begin(), _objectives.end(), &objective);
109 if(it == _objectives.end())
111 std::cout <<
"[ocra::Solver::internalRemoveObjective] Objective was not added in the solver, so it cannot be removed\n" <<
"\tObjective is named: " << objective.getName() << std::endl;
115 _objectives.erase(it);
117 _problemVariable.
remove(&const_cast<GenericObjective*>(&objective)->getVariable());
123 std::vector<const GenericConstraint*>::iterator it = std::find(_constraints.begin(), _constraints.end(), &constraint);
124 if(it == _constraints.end())
126 std::cout <<
"[ocra::Solver::internalRemoveConstraint] Constraint was not added in the solver, or has already been removed, so it cannot be removed\n" <<
"\tConstraint is named: " << constraint.getName() << std::endl;
130 _constraints.erase(it);
133 _problemVariable.
remove(&const_cast<GenericConstraint*>(&constraint)->getVariable());
149 _memory.set_capacity(level);
155 throw std::runtime_error(
"[Solver::setAutoDumpFile] Invalid (empty) filename!");
157 _autodumpFile = file;
173 std::copy(_memory.begin(), _memory.end(), std::ostream_iterator<std::string>(std::cout,
"\r\n\r\n----------------\r\n"));
176 std::ofstream os(file.c_str());
177 std::copy(_memory.begin(), _memory.end(), std::ostream_iterator<std::string>(os,
"\r\n\r\n----------------\r\n"));
void internalAddConstraint(const GenericConstraint &constraint)
virtual Function & getFunction()
void printStatus(std::ostream &os)
void internalRemoveConstraint(const GenericConstraint &constraint)
void insert(Variable *var)
void internalAddObjective(const GenericObjective &objective)
virtual void doPrepare()=0
OptimizationResult _result
void setValue(const VectorXd &val) const
const OptimizationResult & solve()
const std::vector< int > & findMapping(Variable &var)
void connect(T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
Call this method to register a non-static method as a callback.
void internalRemoveObjective(const GenericObjective &objective)
void dump(const std::string &file="") const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
virtual void onObjectiveResize(int timestamp)
void deactivateAutoDump()
virtual void onConstraintResize(int timestamp)
virtual void doConclude()=0
void setAutoDumpFile(const std::string &file)
void remove(Variable *var)
void disconnect(T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
Disconnect non-static method.
This class represents a variable in a mathematical sense.
Declaration file of the Solver class.
virtual const std::string & getMoreInfo() const
const std::vector< int > & getMapping() const
void setMemoryLevel(int level)
const OptimizationResult & getLastResult() const
A class to manage the relative mapping of a variable with respect to another one. ...
virtual Function & getFunction()
VariableMapping * find(Variable *var) const
CompositeVariable & getVariable()
#define ocra_assert(ocra_expression)
virtual std::string toString()=0
void disconnect(Derived &object, void(Base::*callbackToErase)(int)) const
Disconnect non-static method.
void connect(Derived &object, void(Base::*newCallback)(int)) const
Call this method to register a non-static method as a callback.
Declaration file of the VariableMapping class.