67 std::vector<int> viol_idx;
68 for (uint i=0; i<bounds.size(); ++i) {
69 double lower = bounds.at(i).lower_;
70 double upper = bounds.at(i).upper_;
72 if (val < lower-tol || upper+tol < val)
73 viol_idx.push_back(i);
76 std::string black =
"\033[0m";
77 std::string red =
"\033[31m";
78 std::string color = viol_idx.empty()? black : red;
80 std::cout.precision(2);
81 std::cout << std::fixed
83 << std::setw(30) <<
name_ 86 << std::setw(9) << index
91 << std::setw(12) << viol_idx.size()
128 if (c->GetName() == name)
142 int n_rows = c->GetRows();
144 g_all.middleRows(row, n_rows) += g;
157 int n_rows = c->GetRows();
158 c->SetVariables(x.middleRows(row,n_rows));
169 if (n_var == 0)
return jacobian;
172 std::vector< Eigen::Triplet<double> > triplet_list;
175 const Jacobian& jac = c->GetJacobian();
176 triplet_list.reserve(triplet_list.size()+jac.nonZeros());
178 for (
int k=0; k<jac.outerSize(); ++k)
179 for (Jacobian::InnerIterator it(jac,k); it; ++it)
180 triplet_list.push_back(Eigen::Triplet<double>(row+it.row(), it.col(), it.value()));
186 jacobian.setFromTriplets(triplet_list.begin(), triplet_list.end());
196 bounds_.insert(bounds_.end(), b.begin(), b.end());
214 std::cout <<
GetName() <<
":\n";
217 c->Print(tol, index);
219 std::cout << std::endl;
virtual VectorXd GetValues() const =0
Returns the "values" of whatever this component represents.
VecBound GetBounds() const override
Returns the "bounds" of this component.
virtual void Print(double tolerance, int &index_start) const
Prints the relevant information (name, rows, values) of this component.
const Component::Ptr GetComponent(std::string name) const
Access generic component with the specified name.
static const int kSpecifyLater
const ComponentVec GetComponents() const
Returns read access to the components.
Component(int num_rows, const std::string &name)
Creates a component.
std::vector< Component::Ptr > ComponentVec
void ClearComponents()
Removes all component from this composite.
std::string GetName() const
Returns the name (id) of this component.
std::shared_ptr< Component > Ptr
Declares the classes Composite and Component used as variables, costs and constraints.
VectorXd GetValues() const override
Returns the "values" of whatever this component represents.
void SetRows(int num_rows)
Sets the number of rows of this component.
void AddComponent(const Component::Ptr &)
Adds a component to this composite.
Eigen::SparseMatrix< double, Eigen::RowMajor > Jacobian
common namespace for all elements in this library.
Interface representing either Variable, Cost or Constraint.
void SetVariables(const VectorXd &x) override
Sets the optimization variables from an Eigen vector.
Jacobian GetJacobian() const override
Returns derivatives of each row w.r.t. the variables.
Composite(const std::string &name, bool is_cost)
Creates a Composite holding either variables, costs or constraints.
std::vector< Bounds > VecBound
int GetRows() const
Returns the number of rows of this component.
virtual VecBound GetBounds() const =0
Returns the "bounds" of this component.