lemon/lp_glpk.cc
changeset 2364 3a5e67bd42d2
parent 2363 2aabce558574
child 2366 bfbdded3763a
equal deleted inserted replaced
22:a977216453ff 23:c8b350d481d1
   124   {
   124   {
   125     lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
   125     lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
   126 
   126 
   127   }
   127   }
   128   
   128   
   129   void LpGlpk::_setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) 
   129   void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) 
   130   {
   130   {
   131     std::vector<int> indices;
   131     std::vector<int> indices;
   132     std::vector<Value> values;
   132     std::vector<Value> values;
   133 
   133 
   134     indices.push_back(0);
   134     indices.push_back(0);
   135     values.push_back(0);
   135     values.push_back(0);
   136 
   136 
   137     for(LpRowIterator it=b; it!=e; ++it) {
   137     for(ConstRowIterator it=b; it!=e; ++it) {
   138       indices.push_back(it->first);
   138       indices.push_back(it->first);
   139       values.push_back(it->second);
   139       values.push_back(it->second);
   140     }
   140     }
   141 
   141 
   142     lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]);
   142     lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]);
   143   }
   143   }
   144   
   144 
   145   void LpGlpk::_setColCoeffs(int i, LpColIterator b, LpColIterator e) {
   145   void LpGlpk::_getRowCoeffs(int i, RowIterator b) 
       
   146   {
       
   147     int length = lpx_get_mat_row(lp, i, 0, 0);
       
   148     
       
   149     std::vector<int> indices(length + 1);
       
   150     std::vector<Value> values(length + 1);
       
   151     
       
   152     lpx_get_mat_row(lp, i, &indices[0], &values[0]);
       
   153     
       
   154     for (int i = 1; i <= length; ++i) {
       
   155       *b = std::make_pair(indices[i], values[i]);
       
   156       ++b;
       
   157     }
       
   158   }
       
   159   
       
   160   void LpGlpk::_setColCoeffs(int i, ConstColIterator b, ConstColIterator e) {
   146 
   161 
   147     std::vector<int> indices;
   162     std::vector<int> indices;
   148     std::vector<Value> values;
   163     std::vector<Value> values;
   149 
   164 
   150     indices.push_back(0);
   165     indices.push_back(0);
   151     values.push_back(0);
   166     values.push_back(0);
   152 
   167 
   153     for(LpColIterator it=b; it!=e; ++it) {
   168     for(ConstColIterator it=b; it!=e; ++it) {
   154       indices.push_back(it->first);
   169       indices.push_back(it->first);
   155       values.push_back(it->second);
   170       values.push_back(it->second);
   156     }
   171     }
   157     
   172     
   158     lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]);
   173     lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]);
   159   }
   174   }
   160 
   175 
       
   176   void LpGlpk::_getColCoeffs(int i, ColIterator b) 
       
   177   {
       
   178     int length = lpx_get_mat_col(lp, i, 0, 0);
       
   179     
       
   180     std::vector<int> indices(length + 1);
       
   181     std::vector<Value> values(length + 1);
       
   182     
       
   183     lpx_get_mat_col(lp, i, &indices[0], &values[0]);
       
   184     
       
   185     for (int i = 1; i <= length; ++i) {
       
   186       *b = std::make_pair(indices[i], values[i]);
       
   187       ++b;
       
   188     }
       
   189   }
   161 
   190 
   162   void LpGlpk::_setCoeff(int row, int col, Value value) 
   191   void LpGlpk::_setCoeff(int row, int col, Value value) 
   163   {
   192   {
   164 
   193 
   165     if (lpx_get_num_cols(lp) < lpx_get_num_rows(lp)) {
   194     if (lpx_get_num_cols(lp) < lpx_get_num_rows(lp)) {
   221   LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
   250   LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
   222   {
   251   {
   223 
   252 
   224     int length=lpx_get_mat_row(lp, row, 0, 0);
   253     int length=lpx_get_mat_row(lp, row, 0, 0);
   225     
   254     
   226     std::vector<int> indices(length + 2);
   255     std::vector<int> indices(length + 1);
   227     std::vector<Value> values(length + 2);
   256     std::vector<Value> values(length + 1);
   228     
   257     
   229     lpx_get_mat_row(lp, row, &indices[0], &values[0]);
   258     lpx_get_mat_row(lp, row, &indices[0], &values[0]);
   230     
   259     
   231     //The following code does not suppose that the elements of the
   260     //The following code does not suppose that the elements of the
   232     //array indices are sorted
   261     //array indices are sorted