00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #include <coconut_config.h>
00029 #include <dag.h>
00030 #include <model.h>
00031 #include <vector>
00032 #include <algorithm>
00033 #include <g_algo.h>
00034 #include <cmath>
00035 #include <set>
00036 #include <api_exception.h>
00037 #include <array_vector.h>
00038 #include <sparsity.h>
00039
00040 #define SP_DBG 0
00041
00042 namespace coco {
00043
00045
00048 typedef std::pair<unsigned int, unsigned int> ipair;
00050
00054 typedef std::set<ipair> splist;
00055
00057
00062 class sparsity_visitor : public preorder_visitor<expression_node,
00063 const variable_indicator&,
00064 const variable_indicator&>
00065 {
00067 splist& sp_list;
00069 variable_indicator v;
00071 unsigned int numvars;
00073 unsigned int n;
00075 int base;
00076
00077 private:
00080 void make_clique()
00081 {
00082 #if SP_DBG
00083 std::cout << "in make_clique" << std::endl;
00084 #endif
00085 for(unsigned int i=0; i<numvars; i++)
00086 {
00087 if(!v.test(i)) continue;
00088 sp_list.insert(std::make_pair(i+base,i+base));
00089 for(unsigned int j=i+1; j<numvars; j++)
00090 if(v.test(j))
00091 sp_list.insert(std::make_pair(i+base,j+base));
00092 }
00093 }
00094
00098 void make_bipartite(const variable_indicator& __vn)
00099 {
00100 #if SP_DBG
00101 std::cout << "in make_bipartite" << std::endl;
00102 #endif
00103 for(unsigned int i=0; i<numvars; i++)
00104 {
00105 if(!v.test(i)) continue;
00106 for(unsigned int j=0; j<numvars; j++)
00107 if(__vn.test(j))
00108 sp_list.insert(std::make_pair(std::min(i,j)+base,std::max(i,j)+base));
00109 }
00110 }
00111
00112 public:
00116 sparsity_visitor(splist &__o, int __n, bool __b = false) : sp_list(__o),
00117 numvars(__n), base(__b ? 1 : 0)
00118 { }
00119
00121 sparsity_visitor(const sparsity_visitor& __c) : sp_list(__c.sp_list),
00122 v(__c.v), numvars(__c.numvars),
00123 base(__c.base)
00124 { }
00125
00127
00128 bool preorder(const expression_node &r)
00129 {
00130 #if SP_DBG
00131 std::cout << "in preorder: " << r.operator_type << std::endl;
00132 #endif
00133 bool rval = false;
00134 n = 0;
00135
00136 v = r.v_i;
00137
00138 #if SP_DBG
00139 std::cout << "v - after v=r.v_i: " << std::endl;
00140 for(unsigned int i=0; i<numvars; i++)
00141 if(v.test(i)) std::cout << i << " ";
00142 std::cout << std::endl;
00143 #endif
00144
00145 if(r.operator_type < 0)
00146 {
00147 switch(r.operator_type)
00148 {
00149 case EXPRINFO_CONSTANT:
00150 case EXPRINFO_VARIABLE:
00151 case EXPRINFO_LIN:
00152 break;
00153 case EXPRINFO_SUM:
00154 case EXPRINFO_MEAN:
00155 rval = true;
00156 break;
00157 case EXPRINFO_PROD:
00158 case EXPRINFO_SCPROD:
00159 rval = true;
00160 v.clear();
00161 break;
00162 case EXPRINFO_MONOME:
00163 throw nyi_exception("sparsity_evaluator: MONOME!");
00164 break;
00165 case EXPRINFO_INTPOWER:
00166 if(r.params.nn() == 1)
00167 rval = true;
00168 else
00169 make_clique();
00170 break;
00171 case EXPRINFO_POLY:
00172 if(r.params.d().size() <= 2)
00173 rval = true;
00174 else
00175 make_clique();
00176 break;
00177 case EXPRINFO_POW:
00178 case EXPRINFO_INVERT:
00179 case EXPRINFO_DIV:
00180 case EXPRINFO_MAX:
00181 case EXPRINFO_MIN:
00182 case EXPRINFO_SQUARE:
00183 case EXPRINFO_SQROOT:
00184 case EXPRINFO_EXP:
00185 case EXPRINFO_LOG:
00186 case EXPRINFO_SIN:
00187 case EXPRINFO_COS:
00188 case EXPRINFO_ATAN2:
00189 case EXPRINFO_GAUSS:
00190 case EXPRINFO_ABS:
00191 case EXPRINFO_NORM:
00192 case EXPRINFO_LOOKUP:
00193 case EXPRINFO_PWLIN:
00194 case EXPRINFO_SPLINE:
00195 case EXPRINFO_PWCONSTLC:
00196 case EXPRINFO_PWCONSTRC:
00197 case EXPRINFO_IN:
00198 case EXPRINFO_IF:
00199 case EXPRINFO_AND:
00200 case EXPRINFO_OR:
00201 case EXPRINFO_NOT:
00202 case EXPRINFO_IMPLIES:
00203 case EXPRINFO_COUNT:
00204 case EXPRINFO_ALLDIFF:
00205 case EXPRINFO_HISTOGRAM:
00206 case EXPRINFO_LEVEL:
00207 case EXPRINFO_NEIGHBOR:
00208 case EXPRINFO_NOGOOD:
00209 case EXPRINFO_EXPECTATION:
00210 case EXPRINFO_INTEGRAL:
00211 case EXPRINFO_DET:
00212 case EXPRINFO_COND:
00213 case EXPRINFO_PSD:
00214 case EXPRINFO_MPROD:
00215 case EXPRINFO_FEM:
00216 case EXPRINFO_CMPROD:
00217 case EXPRINFO_CGFEM:
00218 make_clique();
00219 break;
00220 case EXPRINFO_QUAD:
00221 for(linalg::matrix<double>::iterator __r = r.params.m().begin();
00222 __r != r.params.m().end(); ++__r)
00223 for(linalg::matrix<double>::OneD::iterator __c = (*__r).begin();
00224 __c != (*__r).end(); ++__c)
00225 if(__c.column() >= __c.row())
00226 sp_list.insert(std::make_pair(__c.row()+base,
00227 __c.column()+base));
00228 break;
00229 default:
00230 throw api_exception(apiee_internal,
00231 std::string("sparsity_evaluator: unknown operator type ")+
00232 convert_to_str(r.operator_type));
00233 break;
00234 }
00235 }
00236 else if(r.operator_type > 0)
00237 {
00238 make_clique();
00239 }
00240 else
00241 throw api_exception(apiee_internal,
00242 std::string("sparsity_evaluator: cannot handle GHOST nodes!"));
00243 return rval;
00244 }
00245
00246 const variable_indicator& vvalue() { return v; }
00247 const variable_indicator& value() { return v; }
00248
00249 void collect(const expression_node &r, const variable_indicator& __v)
00250 {
00251 #if SP_DBG
00252 std::cout << "in collect: " << r.operator_type << std::endl;
00253 #endif
00254
00255 if(r.operator_type < 0)
00256 {
00257 switch(r.operator_type)
00258 {
00259 case EXPRINFO_PROD:
00260 #if SP_DBG
00261 std::cout << "__v - before make_bipartite: " << std::endl;
00262 for(unsigned int i=0; i<numvars; i++)
00263 if(__v.test(i)) std::cout << i << " ";
00264 std::cout << std::endl;
00265 std::cout << "v - before make_bipartite: " << std::endl;
00266 for(unsigned int i=0; i<numvars; i++)
00267 if(v.test(i)) std::cout << i << " ";
00268 std::cout << std::endl;
00269
00270 std::cout << "splist - before make_bipartite: " << std::endl;
00271 for(splist::const_iterator b=sp_list.begin(); b!=sp_list.end(); ++b)
00272 std::cout << b->first << " " << b->second << std::endl;
00273 std::cout << "end splist " << std::endl;
00274 #endif
00275
00276 make_bipartite(__v);
00277
00278 #if SP_DBG
00279 std::cout << "splist - after make_bipartite: " << std::endl;
00280 for(splist::const_iterator b=sp_list.begin(); b!=sp_list.end(); ++b)
00281 std::cout << b->first << " " << b->second << std::endl;
00282 std::cout << "end splist " << std::endl;
00283 #endif
00284
00285 v.set_all(__v);
00286
00287 #if SP_DBG
00288 std::cout << "v - after set_all: " << std::endl;
00289 for(unsigned int i=0; i<numvars; i++)
00290 if(v.test(i)) std::cout << i << " ";
00291 std::cout << std::endl;
00292 #endif
00293
00294 break;
00295 case EXPRINFO_CONSTANT:
00296 case EXPRINFO_VARIABLE:
00297 case EXPRINFO_INVERT:
00298 case EXPRINFO_SUM:
00299 case EXPRINFO_MAX:
00300 case EXPRINFO_MIN:
00301 case EXPRINFO_DIV:
00302 case EXPRINFO_INTPOWER:
00303 case EXPRINFO_SQUARE:
00304 case EXPRINFO_POW:
00305 case EXPRINFO_SQROOT:
00306 case EXPRINFO_EXP:
00307 case EXPRINFO_LOG:
00308 case EXPRINFO_SIN:
00309 case EXPRINFO_COS:
00310 case EXPRINFO_ATAN2:
00311 case EXPRINFO_GAUSS:
00312 case EXPRINFO_LIN:
00313 case EXPRINFO_QUAD:
00314 case EXPRINFO_ABS:
00315 case EXPRINFO_NORM:
00316 case EXPRINFO_LOOKUP:
00317 case EXPRINFO_PWLIN:
00318 case EXPRINFO_SPLINE:
00319 case EXPRINFO_PWCONSTLC:
00320 case EXPRINFO_PWCONSTRC:
00321 case EXPRINFO_IN:
00322 case EXPRINFO_IF:
00323 case EXPRINFO_AND:
00324 case EXPRINFO_OR:
00325 case EXPRINFO_NOT:
00326 case EXPRINFO_IMPLIES:
00327 case EXPRINFO_COUNT:
00328 case EXPRINFO_ALLDIFF:
00329 case EXPRINFO_HISTOGRAM:
00330 case EXPRINFO_LEVEL:
00331 case EXPRINFO_NEIGHBOR:
00332 case EXPRINFO_NOGOOD:
00333 case EXPRINFO_EXPECTATION:
00334 case EXPRINFO_INTEGRAL:
00335 case EXPRINFO_DET:
00336 case EXPRINFO_COND:
00337 case EXPRINFO_PSD:
00338 case EXPRINFO_MPROD:
00339 case EXPRINFO_FEM:
00340 case EXPRINFO_CMPROD:
00341 case EXPRINFO_CGFEM:
00342 break;
00343 case EXPRINFO_SCPROD:
00344 if((n&1) == 0)
00345 v = __v;
00346 else
00347 {
00348 #if SP_DBG
00349 std::cout << "in collect - SCPROD" << std::endl;
00350 #endif
00351 make_bipartite(__v);
00352 }
00353 if(n == r.n_children)
00354 v = r.v_i;
00355 break;
00356 case EXPRINFO_MONOME:
00357 throw nyi_exception("sparsity_evaluator: MONOME!");
00358 break;
00359 default:
00360 throw api_exception(apiee_internal,
00361 std::string("sparsity_evaluator: unknown operator type ")+
00362 convert_to_str(r.operator_type));
00363 break;
00364 }
00365 }
00366 else if(r.operator_type > 0)
00367 {
00368 ;
00369 }
00370 n++;
00371 }
00373 };
00374
00375
00378 static void row2column_wise(std::vector<unsigned int>& ridx,
00379 std::vector<unsigned int>& cidx,
00380 const bool row_one_based,
00381 const bool col_one_based)
00382 {
00383 if (!ridx.empty())
00384 {
00385 unsigned int i,j;
00386
00387 unsigned int roffset = row_one_based ? 1 : 0;
00388 unsigned int coffset = col_one_based ? 1 : 0;
00389
00390
00391
00392 unsigned int maxcol = col_one_based ? 1 : 0;
00393 for (i=1; i<ridx.size(); ++i)
00394 if (cidx[ridx[i]-1-roffset] > maxcol)
00395 maxcol = cidx[ridx[i]-1-roffset];
00396 if (cidx.back() > maxcol)
00397 maxcol = cidx.back();
00398
00399
00400 std::vector<std::vector<unsigned int> > buf(maxcol+1-coffset);
00401
00402
00403 for (i=0; i<ridx.size()-1; ++i)
00404 {
00405 for (j=ridx[i]-roffset; j<ridx[i+1]-roffset; ++j)
00406 buf[cidx[j]-coffset].push_back(i+roffset);
00407 }
00408 for (j=ridx.back()-roffset; j<cidx.size(); ++j)
00409 buf[cidx[j]-coffset].push_back(i+roffset);
00410
00411
00412 ridx.clear();
00413 cidx.clear();
00414
00415
00416 unsigned int last = coffset;
00417 for (std::vector<std::vector<unsigned int> >::const_iterator c=buf.begin();
00418 c!=buf.end(); ++c)
00419 {
00420 ridx.insert(ridx.end(),c->begin(),c->end());
00421 cidx.push_back(last);
00422 last += c->size();
00423 }
00424 }
00425 else
00426 {
00427 ;
00428 }
00429 }
00430
00431
00433
00461 static void _sparsity(const model& DAG, std::vector<unsigned int>& H_ridx,
00462 std::vector<unsigned int>& H_cidx,
00463 std::vector<unsigned int>& J_funidx,
00464 std::vector<unsigned int>& J_varidx,
00465 bool J_with_obj, bool J_obj_is_first, bool org_only,
00466 bool H_upper_only, bool with_H, bool with_J, sp_indexing indexing,
00467 bool fun_one_based, bool var_one_based)
00468 {
00469 unsigned int i=0;
00470
00471 if(with_H)
00472 {
00473 splist sparse_matrix;
00474 sparsity_visitor s(sparse_matrix, DAG.number_of_variables(), var_one_based);
00475
00476 if(!DAG.objective.is_ground())
00477 recursive_preorder_walk_if(DAG.objective, s);
00478
00479 #if SP_DBG
00480 std::cout << "splist - after preorder walk on objective : " << std::endl;
00481 for(splist::const_iterator b=sparse_matrix.begin(); b!=sparse_matrix.end(); ++b)
00482 std::cout << b->first << " " << b->second << std::endl;
00483 std::cout << "end splist " << std::endl;
00484 #endif
00485
00486 for(std::vector<expression_walker>::const_iterator b =
00487 DAG.constraints.begin(); b != DAG.constraints.end(); ++b)
00488 {
00489 #if SP_DBG
00490 std::cout << "constraint properties: " << (*b)->is(ex_bound)
00491 << " " << org_only << " " << (*b)->is(ex_kj) << std::endl;
00492 #endif
00493 if(!((*b)->is(ex_bound) || (org_only && (*b)->is(ex_kj))))
00494 #if SP_DBG
00495 {
00496 std::cout << "call recursive_preorder_walk_if" << std::endl;
00497 #endif
00498 recursive_preorder_walk_if(*b, s);
00499 #if SP_DBG
00500 }
00501 #endif
00502 }
00503
00504 #if SP_DBG
00505 std::cout << "splist - after preorder walks on constraints: " << std::endl;
00506 for(splist::const_iterator b=sparse_matrix.begin(); b!=sparse_matrix.end(); ++b)
00507 std::cout << b->first << " " << b->second << std::endl;
00508 std::cout << "end splist " << std::endl;
00509 #endif
00510
00511 if(indexing == full_indexing)
00512 {
00513
00514 for(splist::iterator b=sparse_matrix.begin(); b!=sparse_matrix.end(); ++b)
00515 {
00516 H_ridx.push_back((*b).first);
00517 if(!H_upper_only && (*b).first != (*b).second)
00518 H_ridx.push_back((*b).second);
00519 }
00520
00521 for(splist::iterator b=sparse_matrix.begin(); b!=sparse_matrix.end(); ++b)
00522 {
00523 H_cidx.push_back((*b).second);
00524 if(!H_upper_only && (*b).first != (*b).second)
00525 H_cidx.push_back((*b).first);
00526 }
00527 }
00528 else
00529
00530 {
00531 if(!H_upper_only)
00532 {
00533 splist _H;
00534 for(splist::iterator b=sparse_matrix.begin(); b!=sparse_matrix.end();
00535 ++b)
00536 if((*b).first != (*b).second)
00537 _H.insert(std::make_pair((*b).second, (*b).first));
00538 sparse_matrix.insert(_H.begin(), _H.end());
00539 }
00540 i = var_one_based ? 1 : 0;
00541 unsigned int last = i-1;
00542 for(splist::iterator b=sparse_matrix.begin(); b!=sparse_matrix.end(); ++b)
00543 {
00544 if(last != (*b).first)
00545 {
00546 for(++last; last != (*b).first; ++last)
00547 H_ridx.push_back(i);
00548 H_ridx.push_back(i);
00549 }
00550 H_cidx.push_back((*b).second);
00551 ++i;
00552 }
00553
00554 if (indexing == column_wise_indexing)
00555 row2column_wise(H_ridx,H_cidx,var_one_based,var_one_based);
00556 }
00557 }
00558
00559 if(with_J)
00560 {
00561 int base = var_one_based ? 1 : 0;
00562 i = fun_one_based ? 1 : 0;
00563 if(J_with_obj && J_obj_is_first)
00564 {
00565 if(indexing == full_indexing)
00566 {
00567 J_funidx.insert(J_funidx.end(),
00568 DAG.objective.is_ground() ? 0 : DAG.objective->sem.dim, i);
00569 ++i;
00570 }
00571 else
00572
00573 {
00574 J_funidx.push_back(i);
00575 if(!DAG.objective.is_ground())
00576 i += DAG.objective->sem.dim;
00577 }
00578 for(unsigned int j=0; j<DAG.number_of_variables(); j++)
00579 {
00580 if(!DAG.objective.is_ground() && DAG.objective->v_i.test(j))
00581 J_varidx.push_back(j+base);
00582 }
00583 }
00584
00585 for(std::vector<expression_walker>::const_iterator
00586 b = DAG.constraints.begin(); b != DAG.constraints.end(); ++b)
00587 {
00588 if((*b)->is(ex_bound) || (org_only && (*b)->is(ex_kj))) continue;
00589 if(indexing == full_indexing)
00590 {
00591 J_funidx.insert(J_funidx.end(), (*b)->sem.dim, i);
00592 ++i;
00593 }
00594 else
00595 {
00596 J_funidx.push_back(i);
00597 i += (*b)->sem.dim;
00598 }
00599 for(unsigned int j=0; j<DAG.number_of_variables(); j++)
00600 {
00601 if((*b)->v_i.test(j))
00602 J_varidx.push_back(j+base);
00603 }
00604 }
00605 if(J_with_obj && !J_obj_is_first)
00606 {
00607 if(indexing == full_indexing)
00608 J_funidx.insert(J_funidx.end(),
00609 DAG.objective.is_ground() ? 0 : DAG.objective->sem.dim, i);
00610 else
00611 J_funidx.push_back(i);
00612 for(unsigned int j=0; j<DAG.number_of_variables(); j++)
00613 {
00614 if(!DAG.objective.is_ground() && DAG.objective->v_i.test(j))
00615 J_varidx.push_back(j+base);
00616 }
00617 }
00618
00619
00620 if (indexing == column_wise_indexing)
00621 row2column_wise(J_funidx,J_varidx,fun_one_based,var_one_based);
00622
00623 }
00624 }
00625
00626 void sparsity(const model& DAG, std::vector<unsigned int>& H_ridx,
00627 std::vector<unsigned int>& H_cidx,
00628 std::vector<unsigned int>& J_funidx,
00629 std::vector<unsigned int>& J_varidx,
00630 bool J_with_obj, bool J_obj_is_first, bool org_only,
00631 bool H_upper_only, sp_indexing indexing, bool fun_one_based,
00632 bool var_one_based)
00633 {
00634 _sparsity(DAG, H_ridx, H_cidx, J_funidx, J_varidx, J_with_obj, J_obj_is_first,
00635 org_only, H_upper_only, true, true, indexing, fun_one_based,
00636 var_one_based);
00637 }
00638
00639 void sparsity(const model& DAG, std::vector<unsigned int>& H_ridx,
00640 std::vector<unsigned int>& H_cidx,
00641 bool org_only, bool H_upper_only,
00642 sp_indexing indexing, bool var_one_based)
00643 {
00644 std::vector<unsigned int> _dummy;
00645 _sparsity(DAG, H_ridx, H_cidx, _dummy, _dummy, false, false, org_only,
00646 H_upper_only, true, false, indexing, false, var_one_based);
00647 }
00648
00649 void sparsity(const model& DAG, std::vector<unsigned int>& J_funidx,
00650 std::vector<unsigned int>& J_varidx,
00651 bool J_with_obj, bool J_obj_is_first, bool org_only,
00652 sp_indexing indexing, bool fun_one_based, bool var_one_based)
00653 {
00654 std::vector<unsigned int> _dummy;
00655 _sparsity(DAG, _dummy, _dummy, J_funidx, J_varidx, J_with_obj, J_obj_is_first,
00656 org_only, false, false, true, indexing, fun_one_based,
00657 var_one_based);
00658 }
00659
00660 void sparsity(const model& DAG, unsigned int &nnz_H, unsigned int *&H_ridx,
00661 unsigned int *&H_cidx, unsigned int &nnz_J,
00662 unsigned int *&J_funidx, unsigned int *&J_varidx,
00663 bool J_with_obj, bool J_obj_is_first, bool org_only,
00664 bool H_upper_only, sp_indexing indexing, bool fun_one_based,
00665 bool var_one_based)
00666 {
00667 std::vector<unsigned int> _Hr;
00668 std::vector<unsigned int> _Hc;
00669 std::vector<unsigned int> _Jf;
00670 std::vector<unsigned int> _Jv;
00671 array_vector<unsigned int> __h;
00672
00673 _sparsity(DAG, _Hr, _Hc, _Jf, _Jv, J_with_obj, J_obj_is_first, org_only,
00674 H_upper_only, true, true, indexing, fun_one_based, var_one_based);
00675 nnz_H = _Hc.size();
00676 H_ridx = new unsigned int [_Hr.size()];
00677 H_cidx = new unsigned int [nnz_H];
00678 nnz_J = _Jv.size();
00679 J_funidx = new unsigned int [_Jf.size()];
00680 J_varidx = new unsigned int [nnz_J];
00681
00682 __h.assignvector(H_ridx, _Hr.size());
00683 __h.copy_into(_Hr);
00684 __h.assignvector(H_cidx, nnz_H);
00685 __h.copy_into(_Hc);
00686 __h.assignvector(J_funidx, _Jf.size());
00687 __h.copy_into(_Jf);
00688 __h.assignvector(J_varidx, nnz_J);
00689 __h.copy_into(_Jv);
00690 }
00691
00692 void sparsity(const model& DAG, int &nnz_H, int *&H_ridx, int *&H_cidx,
00693 int &nnz_J, int *&J_funidx, int *&J_varidx,
00694 bool J_with_obj, bool J_obj_is_first, bool org_only,
00695 bool H_upper_only, sp_indexing indexing, bool fun_one_based,
00696 bool var_one_based)
00697 {
00698 sparsity(DAG, *(unsigned int *)&nnz_H, (unsigned int *&)H_ridx,
00699 (unsigned int *&)H_cidx, *(unsigned int *)&nnz_J,
00700 (unsigned int *&)J_funidx, (unsigned int *&)J_varidx, J_with_obj,
00701 J_obj_is_first, org_only, H_upper_only, indexing,
00702 fun_one_based, var_one_based);
00703 }
00704
00705 void sparsity(const model& DAG, unsigned int &nnz_H,
00706 unsigned int *&H_ridx, unsigned int *&H_cidx, bool org_only,
00707 bool H_upper_only, sp_indexing indexing, bool fun_one_based,
00708 bool var_one_based)
00709 {
00710 std::vector<unsigned int> _Hr;
00711 std::vector<unsigned int> _Hc;
00712 std::vector<unsigned int> _dummy;
00713 array_vector<unsigned int> __h;
00714
00715 _sparsity(DAG, _Hr, _Hc, _dummy, _dummy, false, false, org_only, H_upper_only,
00716 true, false, indexing, fun_one_based, var_one_based);
00717 nnz_H = _Hc.size();
00718 H_ridx = new unsigned int [_Hr.size()];
00719 H_cidx = new unsigned int [nnz_H];
00720
00721 __h.assignvector(H_ridx, _Hr.size());
00722 __h.copy_into(_Hr);
00723 __h.assignvector(H_cidx, nnz_H);
00724 __h.copy_into(_Hc);
00725 }
00726
00727 void sparsity(const model& DAG, int &nnz_H, int *&H_ridx, int *&H_cidx,
00728 bool org_only, bool H_upper_only, sp_indexing indexing,
00729 bool var_one_based)
00730 {
00731 sparsity(DAG, *(unsigned int*)&nnz_H, (unsigned int *&)H_ridx,
00732 (unsigned int *&)H_cidx, org_only, H_upper_only, indexing,
00733 false, var_one_based);
00734 }
00735
00736 void sparsity(const model& DAG, unsigned int &nnz_J, unsigned int *&J_funidx,
00737 unsigned int *&J_varidx, bool J_with_obj, bool J_obj_is_first,
00738 bool org_only, sp_indexing indexing, bool fun_one_based,
00739 bool var_one_based)
00740 {
00741 std::vector<unsigned int> _dummy;
00742 std::vector<unsigned int> _Jf;
00743 std::vector<unsigned int> _Jv;
00744 array_vector<unsigned int> __h;
00745
00746 _sparsity(DAG, _dummy, _dummy, _Jf, _Jv, J_with_obj, J_obj_is_first,
00747 org_only, false, false, true, indexing, fun_one_based,
00748 var_one_based);
00749 nnz_J = _Jv.size();
00750 J_funidx = new unsigned int [_Jf.size()];
00751 J_varidx = new unsigned int [nnz_J];
00752
00753 __h.assignvector(J_funidx, _Jf.size());
00754 __h.copy_into(_Jf);
00755 __h.assignvector(J_varidx, nnz_J);
00756 __h.copy_into(_Jv);
00757 }
00758
00759
00760 void sparsity(const model& DAG, int &nnz_J, int *&J_funidx, int *&J_varidx,
00761 bool J_with_obj, bool J_obj_is_first, bool org_only,
00762 sp_indexing indexing, bool fun_one_based, bool var_one_based)
00763 {
00764 sparsity(DAG, *(unsigned int *)&nnz_J, (unsigned int *&)J_funidx,
00765 (unsigned int *&)J_varidx, J_with_obj, J_obj_is_first, org_only,
00766 indexing, fun_one_based, var_one_based);
00767 }
00768
00769
00770 }