@@ -42,7 +42,7 @@ namespace roboptim
4242 {
4343 using namespace boost ;
4444
45- n = static_cast <Index> (solver_. problem (). function (). inputSize ());
45+ n = static_cast <Index> (costFunction_-> inputSize ());
4646 m = static_cast <Index> (constraintsOutputSize ());
4747
4848 function_t ::vector_t x (n);
@@ -56,18 +56,12 @@ namespace roboptim
5656
5757 // compute number of non zeros elements in jacobian constraint.
5858 nnz_jac_g = 0 ;
59- typedef solver_t :: problem_t :: constraints_t ::const_iterator
59+ typedef std::vector<differentiableFunctionPtr_t> ::const_iterator
6060 citer_t ;
61- for (citer_t it = solver_. problem (). constraints () .begin ();
62- it != solver_. problem (). constraints () .end (); ++it)
61+ for (citer_t it = differentiableConstraintFunctions_ .begin ();
62+ it != differentiableConstraintFunctions_ .end (); ++it)
6363 {
64- shared_ptr<solver_t ::commonConstraintFunction_t> g;
65- if (it->which () == LINEAR )
66- g = get<shared_ptr<linearFunction_t> > (*it);
67- else
68- g = get<shared_ptr<nonLinearFunction_t> > (*it);
69-
70- nnz_jac_g += g->jacobian (x).nonZeros ();
64+ nnz_jac_g += (*it)->jacobian (x).nonZeros ();
7165 }
7266
7367
@@ -87,14 +81,14 @@ namespace roboptim
8781 using namespace boost ;
8882 ROBOPTIM_DEBUG_ONLY
8983 (function_t ::size_type n_ = static_cast <function_t ::size_type> (n));
90- assert (solver_. problem (). function (). inputSize () == n_);
84+ assert (costFunction_-> inputSize () == n_);
9185 assert (constraintsOutputSize () == m);
9286
9387 if (!jacobian_)
9488 {
95- jacobian_ = function_t ::jacobian_t
96- (static_cast <function_t ::matrix_t ::Index> (constraintsOutputSize ()),
97- solver_. problem (). function (). inputSize ());
89+ jacobian_ = differentiableFunction_t ::jacobian_t
90+ (static_cast <differentiableFunction_t ::matrix_t ::Index> (constraintsOutputSize ()),
91+ costFunction_-> inputSize ());
9892 jacobian_->reserve (nele_jac);
9993 }
10094
@@ -111,15 +105,15 @@ namespace roboptim
111105 // First evaluate the constraints in zero to build the
112106 // constraints jacobian.
113107 int idx = 0 ;
114- typedef solver_t :: problem_t :: constraints_t ::const_iterator
108+ typedef std::vector<differentiableFunctionPtr_t> ::const_iterator
115109 citer_t ;
116110 unsigned constraintId = 0 ;
117111
118112 typedef Eigen::Triplet<double > triplet_t ;
119113 std::vector<triplet_t > coefficients;
120114
121- for (citer_t it = solver_. problem (). constraints () .begin ();
122- it != solver_. problem (). constraints () .end ();
115+ for (citer_t it = differentiableConstraintFunctions_ .begin ();
116+ it != differentiableConstraintFunctions_ .end ();
123117 ++it, ++constraintId)
124118 {
125119 LOG4CXX_TRACE
@@ -160,23 +154,17 @@ namespace roboptim
160154 else // other use initial guess.
161155 x = *(solver_.problem ().startingPoint ());
162156
163- shared_ptr<solver_t ::commonConstraintFunction_t> g;
164- if (it->which () == LINEAR )
165- g = get<shared_ptr<linearFunction_t> > (*it);
166- else
167- g = get<shared_ptr<nonLinearFunction_t> > (*it);
168-
169- function_t ::jacobian_t jacobian = g->jacobian (x);
157+ differentiableFunction_t::jacobian_t jacobian = (*it)->jacobian (x);
170158 for (int k = 0 ; k < jacobian.outerSize (); ++k)
171- for (function_t ::jacobian_t ::InnerIterator
159+ for (differentiableFunction_t ::jacobian_t ::InnerIterator
172160 it (jacobian, k); it; ++it)
173161 {
174162 const int row = static_cast <int > (idx + it.row ());
175163 const int col = static_cast <int > (it.col ());
176164 coefficients.push_back
177165 (triplet_t (row, col, it.value ()));
178166 }
179- idx += g ->outputSize ();
167+ idx += (*it) ->outputSize ();
180168 }
181169
182170 jacobian_->setFromTriplets
@@ -190,7 +178,7 @@ namespace roboptim
190178 idx = 0 ;
191179
192180 for (int k = 0 ; k < jacobian_->outerSize (); ++k)
193- for (function_t ::jacobian_t ::InnerIterator it (*jacobian_, k);
181+ for (differentiableFunction_t ::jacobian_t ::InnerIterator it (*jacobian_, k);
194182 it; ++it)
195183 {
196184 iRow[idx] = it.row (), jCol[idx] = it.col ();
@@ -208,35 +196,29 @@ namespace roboptim
208196
209197 Eigen::Map<const function_t ::vector_t > x_ (x, n);
210198
211- typedef solver_t :: problem_t :: constraints_t ::const_iterator
199+ typedef std::vector<differentiableFunctionPtr_t> ::const_iterator
212200 citer_t ;
213201
214202 int idx = 0 ;
215203 int constraintId = 0 ;
216- for (citer_t it = solver_. problem (). constraints () .begin ();
217- it != solver_. problem (). constraints () .end (); ++it)
204+ for (citer_t it = differentiableConstraintFunctions_ .begin ();
205+ it != differentiableConstraintFunctions_ .end (); ++it)
218206 {
219- shared_ptr<solver_t ::commonConstraintFunction_t> g;
220- if (it->which () == LINEAR )
221- g = get<shared_ptr<linearFunction_t> > (*it);
222- else
223- g = get<shared_ptr<nonLinearFunction_t> > (*it);
224-
225207 // TODO: use middleRows once Eigen is fixed
226208 // TODO: avoid allocation here (may be solved with
227209 // http://eigen.tuxfamily.org/bz/show_bug.cgi?id=910)
228- copySparseBlock (*jacobian_, g ->jacobian (x_), idx, 0 );
229- idx += g ->outputSize ();
210+ copySparseBlock (*jacobian_, (*it) ->jacobian (x_), idx, 0 );
211+ idx += (*it) ->outputSize ();
230212
231213 IpoptCheckGradient
232- (*g , 0 , x_,
214+ (*(*it) , 0 , x_,
233215 constraintId++, solver_);
234216 }
235217
236218 // Copy jacobian values from internal sparse matrix.
237219 idx = 0 ;
238220 for (int k = 0 ; k < jacobian_->outerSize (); ++k)
239- for (function_t ::jacobian_t ::InnerIterator it (*jacobian_, k);
221+ for (differentiableFunction_t ::jacobian_t ::InnerIterator it (*jacobian_, k);
240222 it; ++it)
241223 {
242224 assert (idx < nele_jac);
0 commit comments