Changeset 1074:4a24a46407db in lemon-0.x for src/work/marci/lp
- Timestamp:
- 01/11/05 18:15:46 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1470
- Location:
- src/work/marci/lp
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/lp/lp_solver_wrapper_3.h
r1048 r1074 169 169 /// \e 170 170 typedef IterablePartition<int>::ClassIt ColIt; 171 p rotected:171 public: 172 172 /// \e 173 173 IterablePartition<int> row_iter_map; … … 175 175 IterablePartition<int> col_iter_map; 176 176 /// \e 177 const int VALID_ ID;178 /// \e 179 const int INVALID_ ID;177 const int VALID_CLASS; 178 /// \e 179 const int INVALID_CLASS; 180 180 public: 181 181 /// \e 182 182 LPSolverBase() : row_iter_map(2), 183 183 col_iter_map(2), 184 VALID_ ID(0), INVALID_ID(1) { }184 VALID_CLASS(0), INVALID_CLASS(1) { } 185 185 /// \e 186 186 virtual ~LPSolverBase() { } … … 189 189 /// \e 190 190 virtual void setMaximize() = 0; 191 /// \e 192 virtual RowIt addRow() = 0; 193 /// \e 194 virtual ColIt addCol() = 0; 195 /// temporally, glpk style indexing 196 virtual void setRowCoeffs(RowIt row_it, int num, 197 int* indices, _Value* doubles) = 0; 198 //pair<RowIt, _Value>-bol kell megadni egy std range-et 191 protected: 192 /// \e 193 virtual int _addRow() = 0; 194 /// \e 195 virtual int _addCol() = 0; 196 public: 197 /// \e 198 RowIt addRow() { 199 int i=_addRow(); 200 RowIt row_it; 201 row_iter_map.first(row_it, INVALID_CLASS); 202 if (row_iter_map.valid(row_it)) { //van hasznalhato hely 203 row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS); 204 row_iter_map[row_it]=i; 205 } else { //a cucc vegere kell inzertalni mert nincs szabad hely 206 row_it=row_iter_map.push_back(i, VALID_CLASS); 207 } 208 return row_it; 209 } 210 /// \e 211 ColIt addCol() { 212 int i=_addCol(); 213 ColIt col_it; 214 col_iter_map.first(col_it, INVALID_CLASS); 215 if (col_iter_map.valid(col_it)) { //van hasznalhato hely 216 col_iter_map.set(col_it, INVALID_CLASS, VALID_CLASS); 217 col_iter_map[col_it]=i; 218 } else { //a cucc vegere kell inzertalni mert nincs szabad hely 219 col_it=col_iter_map.push_back(i, VALID_CLASS); 220 } 221 return col_it; 222 } 223 /// \e 224 virtual void setRowCoeffs(int i, 225 std::vector<std::pair<int, double> > coeffs) = 0; 226 /// \e 227 virtual void setColCoeffs(int i, 228 std::vector<std::pair<int, double> > coeffs) = 0; 199 229 /// \e 200 230 template <typename Begin, typename End> 201 231 void setRowCoeffs(RowIt row_it, Begin begin, End end) { 202 int mem_length=1+colNum(); 203 int* indices = new int[mem_length]; 204 _Value* doubles = new _Value[mem_length]; 205 int length=0; 232 std::vector<std::pair<int, double> > coeffs; 206 233 for ( ; begin!=end; ++begin) { 207 ++length; 208 indices[length]=col_iter_map[begin->first]; 209 doubles[length]=begin->second; 210 } 211 setRowCoeffs(row_it, length, indices, doubles); 212 delete [] indices; 213 delete [] doubles; 214 } 215 /// temporally, glpk style indexing 216 virtual void setColCoeffs(ColIt col_it, int num, 217 int* indices, _Value* doubles) = 0; 218 //pair<ColIt, _Value>-bol kell megadni egy std range-et 234 coeffs.push_back(std:: 235 make_pair(col_iter_map[begin->first], begin->second)); 236 } 237 setRowCoeffs(row_iter_map[row_it], coeffs); 238 } 219 239 /// \e 220 240 template <typename Begin, typename End> 221 241 void setColCoeffs(ColIt col_it, Begin begin, End end) { 222 int mem_length=1+rowNum(); 223 int* indices = new int[mem_length]; 224 _Value* doubles = new _Value[mem_length]; 225 int length=0; 242 std::vector<std::pair<int, double> > coeffs; 226 243 for ( ; begin!=end; ++begin) { 227 ++length; 228 indices[length]=row_iter_map[begin->first]; 229 doubles[length]=begin->second; 230 } 231 setColCoeffs(col_it, length, indices, doubles); 232 delete [] indices; 233 delete [] doubles; 234 } 235 /// \e 236 virtual void eraseCol(const ColIt& col_it) = 0; 237 /// \e 238 virtual void eraseRow(const RowIt& row_it) = 0; 244 coeffs.push_back(std:: 245 make_pair(row_iter_map[begin->first], begin->second)); 246 } 247 setColCoeffs(col_iter_map[col_it], coeffs); 248 } 249 /// temporally, glpk style indexing 250 //virtual void setRowCoeffs(RowIt row_it, int num, 251 // int* indices, _Value* doubles) = 0; 252 //pair<RowIt, _Value>-bol kell megadni egy std range-et 253 /// \e 254 // virtual void seColCoeffs(int i, 255 // std::vector<std::pair<int, double> > coeffs) = 0; 256 /// \e 257 // template <typename Begin, typename End> 258 // void setRowCoeffs(RowIt row_it, Begin begin, End end) { 259 // int mem_length=1+colNum(); 260 // int* indices = new int[mem_length]; 261 // _Value* doubles = new _Value[mem_length]; 262 // int length=0; 263 // for ( ; begin!=end; ++begin) { 264 // ++length; 265 // indices[length]=col_iter_map[begin->first]; 266 // doubles[length]=begin->second; 267 // } 268 // setRowCoeffs(row_it, length, indices, doubles); 269 // delete [] indices; 270 // delete [] doubles; 271 // } 272 /// temporally, glpk style indexing 273 //virtual void setColCoeffs(ColIt col_it, int num, 274 // int* indices, _Value* doubles) = 0; 275 //pair<ColIt, _Value>-bol kell megadni egy std range-et 276 /// \e 277 // template <typename Begin, typename End> 278 // void setColCoeffs(ColIt col_it, Begin begin, End end) { 279 // int mem_length=1+rowNum(); 280 // int* indices = new int[mem_length]; 281 // _Value* doubles = new _Value[mem_length]; 282 // int length=0; 283 // for ( ; begin!=end; ++begin) { 284 // ++length; 285 // indices[length]=row_iter_map[begin->first]; 286 // doubles[length]=begin->second; 287 // } 288 // setColCoeffs(col_it, length, indices, doubles); 289 // delete [] indices; 290 // delete [] doubles; 291 // } 292 protected: 293 /// \e 294 virtual void _eraseCol(int i) = 0; 295 /// \e 296 virtual void _eraseRow(int i) = 0; 297 public: 298 /// \e 299 void eraseCol(const ColIt& col_it) { 300 col_iter_map.set(col_it, VALID_CLASS, INVALID_CLASS); 301 int cols[2]; 302 cols[1]=col_iter_map[col_it]; 303 _eraseCol(cols[1]); 304 col_iter_map[col_it]=0; //glpk specifikus, de kell ez?? 305 ColIt it; 306 for (col_iter_map.first(it, VALID_CLASS); 307 col_iter_map.valid(it); col_iter_map.next(it)) { 308 if (col_iter_map[it]>cols[1]) --col_iter_map[it]; 309 } 310 } 311 /// \e 312 void eraseRow(const RowIt& row_it) { 313 row_iter_map.set(row_it, VALID_CLASS, INVALID_CLASS); 314 int rows[2]; 315 rows[1]=row_iter_map[row_it]; 316 _eraseRow(rows[1]); 317 row_iter_map[row_it]=0; //glpk specifikus, de kell ez?? 318 RowIt it; 319 for (row_iter_map.first(it, VALID_CLASS); 320 row_iter_map.valid(it); row_iter_map.next(it)) { 321 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; 322 } 323 } 239 324 /// \e 240 325 virtual void setColBounds(const ColIt& col_it, int bound_type, … … 295 380 typedef LPSolverBase<double> Parent; 296 381 297 // class Row {298 // protected:299 // int i;300 // public:301 // Row() { }302 // Row(const Invalid&) : i(0) { }303 // Row(const int& _i) : i(_i) { }304 // operator int() const { return i; }305 // };306 // class RowIt : public Row {307 // public:308 // RowIt(const Row& row) : Row(row) { }309 // };310 311 // class Col {312 // protected:313 // int i;314 // public:315 // Col() { }316 // Col(const Invalid&) : i(0) { }317 // Col(const int& _i) : i(_i) { }318 // operator int() const { return i; }319 // };320 // class ColIt : public Col {321 // ColIt(const Col& col) : Col(col) { }322 // };323 324 382 public: 325 383 /// \e … … 344 402 lpx_set_obj_dir(lp, LPX_MAX); 345 403 } 346 /// \e 347 ColIt addCol() { 348 int i=lpx_add_cols(lp, 1); 349 ColIt col_it; 350 col_iter_map.first(col_it, INVALID_ID); 351 if (col_iter_map.valid(col_it)) { //van hasznalhato hely 352 col_iter_map.set(col_it, INVALID_ID, VALID_ID); 353 col_iter_map[col_it]=i; 354 //col_id_to_lp_col_id[col_iter_map[col_it]]=i; 355 } else { //a cucc vegere kell inzertalni mert nincs szabad hely 356 //col_id_to_lp_col_id.push_back(i); 357 //int j=col_id_to_lp_col_id.size()-1; 358 col_it=col_iter_map.push_back(i, VALID_ID); 359 } 360 // edge_index_map.set(e, i); 361 // lpx_set_col_bnds(lp, i, LPX_DB, 0.0, 1.0); 362 // lpx_set_obj_coef(lp, i, cost[e]); 363 return col_it; 364 } 365 /// \e 366 RowIt addRow() { 367 int i=lpx_add_rows(lp, 1); 368 RowIt row_it; 369 row_iter_map.first(row_it, INVALID_ID); 370 if (row_iter_map.valid(row_it)) { //van hasznalhato hely 371 row_iter_map.set(row_it, INVALID_ID, VALID_ID); 372 row_iter_map[row_it]=i; 373 } else { //a cucc vegere kell inzertalni mert nincs szabad hely 374 row_it=row_iter_map.push_back(i, VALID_ID); 375 } 376 return row_it; 377 } 404 protected: 405 /// \e 406 int _addCol() { 407 return lpx_add_cols(lp, 1); 408 } 409 /// \e 410 int _addRow() { 411 return lpx_add_rows(lp, 1); 412 } 413 public: 378 414 using Parent::setRowCoeffs; 379 void setRowCoeffs(RowIt row_it, int length, 380 int* indices, double* doubles) { 381 lpx_set_mat_row(lp, row_iter_map[row_it], length, indices, doubles); 382 } 383 using Parent::setColCoeffs; 384 void setColCoeffs(ColIt col_it, int length, 385 int* indices, double* doubles) { 386 lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles); 387 } 415 /// \e 416 virtual void setRowCoeffs(int i, 417 std::vector<std::pair<int, double> > coeffs) { 418 int mem_length=1+colNum(); 419 int* indices = new int[mem_length]; 420 double* doubles = new double[mem_length]; 421 int length=0; 422 for (std::vector<std::pair<int, double> >:: 423 const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) { 424 ++length; 425 indices[length]=it->first; 426 doubles[length]=it->second; 427 std::cout << " " << indices[length] << " " 428 << doubles[length] << std::endl; 429 } 430 std::cout << i << " " << length << std::endl; 431 lpx_set_mat_row(lp, i, length, indices, doubles); 432 delete [] indices; 433 delete [] doubles; 434 } 435 /// \e 436 virtual void setColCoeffs(int i, 437 std::vector<std::pair<int, double> > coeffs) { 438 int mem_length=1+rowNum(); 439 int* indices = new int[mem_length]; 440 double* doubles = new double[mem_length]; 441 int length=0; 442 for (std::vector<std::pair<int, double> >:: 443 const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) { 444 ++length; 445 indices[length]=it->first; 446 doubles[length]=it->second; 447 } 448 lpx_set_mat_col(lp, i, length, indices, doubles); 449 delete [] indices; 450 delete [] doubles; 451 } 452 // /// \e 453 // /// temporally, glpk style indexing 454 // virtual void setRowCoeffs(RowIt row_it, int num, 455 // int* indices, _Value* doubles) = 0; 456 // //pair<RowIt, _Value>-bol kell megadni egy std range-et 457 // /// \e 458 // template <typename Begin, typename End> 459 // void setRowCoeffs(RowIt row_it, Begin begin, End end) { 460 // int mem_length=1+colNum(); 461 // int* indices = new int[mem_length]; 462 // _Value* doubles = new _Value[mem_length]; 463 // int length=0; 464 // for ( ; begin!=end; ++begin) { 465 // ++length; 466 // indices[length]=col_iter_map[begin->first]; 467 // doubles[length]=begin->second; 468 // } 469 // setRowCoeffs(row_it, length, indices, doubles); 470 // delete [] indices; 471 // delete [] doubles; 472 // } 473 // void setRowCoeffs(RowIt row_it, int length, 474 // int* indices, double* doubles) { 475 // lpx_set_mat_row(lp, row_iter_map[row_it], length, indices, doubles); 476 // } 477 // using Parent::setColCoeffs; 478 // void setColCoeffs(ColIt col_it, int length, 479 // int* indices, double* doubles) { 480 // lpx_set_mat_col(lp, col_iter_map[col_it], length, indices, doubles); 481 // } 388 482 // //pair<RowIt, double>-bol kell megadni egy std range-et 389 483 // /// \e … … 423 517 // } 424 518 /// \e 425 void eraseCol(const ColIt& col_it) {426 col_iter_map.set(col_it, VALID_ID, INVALID_ID);519 protected: 520 virtual void _eraseCol(int i) { 427 521 int cols[2]; 428 cols[1]= col_iter_map[col_it];522 cols[1]=i; 429 523 lpx_del_cols(lp, 1, cols); 430 col_iter_map[col_it]=0; //glpk specifikus 431 ColIt it; 432 for (col_iter_map.first(it, VALID_ID); 433 col_iter_map.valid(it); col_iter_map.next(it)) { 434 if (col_iter_map[it]>cols[1]) --col_iter_map[it]; 435 } 436 } 437 /// \e 438 void eraseRow(const RowIt& row_it) { 439 row_iter_map.set(row_it, VALID_ID, INVALID_ID); 524 } 525 virtual void _eraseRow(int i) { 440 526 int rows[2]; 441 rows[1]= row_iter_map[row_it];527 rows[1]=i; 442 528 lpx_del_rows(lp, 1, rows); 443 row_iter_map[row_it]=0; //glpk specifikus 444 RowIt it; 445 for (row_iter_map.first(it, VALID_ID); 446 row_iter_map.valid(it); row_iter_map.next(it)) { 447 if (row_iter_map[it]>rows[1]) --row_iter_map[it]; 448 } 449 } 529 } 530 public: 450 531 /// \e 451 532 void setColBounds(const ColIt& col_it, int bound_type, -
src/work/marci/lp/min_cost_gen_flow.h
r1033 r1074 15 15 //#include <preflow_res.h> 16 16 #include <work/marci/merge_node_graph_wrapper.h> 17 #include <work/marci/lp/lp_solver_wrapper_ 2.h>17 #include <work/marci/lp/lp_solver_wrapper_3.h> 18 18 19 19 namespace lemon { … … 229 229 lp.setObjCoef(col_it, cost[e]); 230 230 } 231 LPSolver::ColIt col_it; 232 for (lp.col_iter_map.first(col_it, lp.VALID_CLASS); 233 lp.col_iter_map.valid(col_it); 234 lp.col_iter_map.next(col_it)) { 235 std::cout << "ize " << lp.col_iter_map[col_it] << std::endl; 236 } 231 237 for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { 232 238 typename Graph::template EdgeMap<Num> coeffs(g, 0); … … 245 251 } 246 252 //std::cout << std::endl; 253 std::cout << " " << g.id(n) << " " << row.size() << std::endl; 247 254 lp.setRowCoeffs(row_it, row.begin(), row.end()); 248 255 lp.setRowBounds(row_it, LPX_FX, 0.0, 0.0);
Note: See TracChangeset
for help on using the changeset viewer.