90 if (c->GetName() == name)
105 int n_rows = c->GetRows();
107 g_all.middleRows(row, n_rows) += g;
121 int n_rows = c->GetRows();
122 c->SetVariables(x.middleRows(row,n_rows));
130 int n_var =
components_.front()->GetJacobian().cols();
136 const Jacobian& jac = c->GetJacobian();
137 for (
int k=0; k<jac.outerSize(); ++k)
138 for (Jacobian::InnerIterator it(jac,k); it; ++it)
139 jacobian.coeffRef(row+it.row(), it.col()) += it.value();
154 bounds_.insert(bounds_.end(), b.begin(), b.end());
173 std::cout <<
GetName() <<
":\n";
178 std::cout << std::endl;
184 std::string end_string =
", ...";
195 std::vector<int> viol_idx;
197 for (uint i=0; i<bounds.size(); ++i) {
198 double lower = bounds.at(i).lower_;
199 double upper = bounds.at(i).upper_;
201 if (val < lower-eps || upper+eps < val)
202 viol_idx.push_back(i);
206 std::cout.precision(2);
207 std::cout << std::fixed;
209 std::string black =
"\033[0m";
210 std::string red =
"\033[31m";
211 std::string color = viol_idx.empty()? black : red;
212 std::cout <<
name_ <<
"\t(";
214 std::cout <<
", " << color <<
"nr_violated=" << viol_idx.size() <<
" ( ";
216 int nr_indices_print = viol_idx.size()<i_print? viol_idx.size() : i_print;
217 for (
int i=0; i<nr_indices_print; ++i)
218 std::cout << viol_idx.at(i) <<
", ";
228 for (
int i=1; i<val.rows(); ++i)
229 std::cout <<
",\t" << val(i);
231 std::cout << end_string << std::endl;
VecBound GetBounds() const override
Returns the "bounds" 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
Interface representing either Variable, Cost or Constraint.
void Print() const override
Prints the relevant information (name, rows, values) of this component.
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.
virtual void Print() const
Prints the relevant information (name, rows, values) of this component.
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.