Beispiel #1
0
void MtxLP::setLenObjective(strvec cols, bool tmp){
    if (kind != MILP)
        throw runtime_error("trying to optimise length using a non-MILP solver!");
    emptyObjective();
    int contcoef = isMaximising() ? 1 : -1;
    int intcoef = -contcoef;
    for (strvec::iterator it = cols.begin(); it != cols.end(); ++it){
        string name = *it;
        string intname = get_int_name(name);
        stomap *sto = new stomap;
        (*sto)[name] = contcoef;
        (*sto)[intname] = intcoef * vmax;
        addConstraint(sto, 0, UB, tmp, name + INT_CONSTR_TAG);
        setObjCoef(intname, 1);
        delete sto;
    }
}
Beispiel #2
0
void MtxLP::updateObjCoef(string col, double coef){
    coef += getObjCoef(col);
    setObjCoef(col, coef);
}
Beispiel #3
0
void MtxLP::setObjective(stomap* sto){
    for (stomap::iterator i = sto->begin(); i != sto->end(); ++i)
        setObjCoef(i->first, i->second);
}
Beispiel #4
0
void MtxLP::setObjective(strvec names, double coef){
    emptyObjective();
    for (strvec::iterator it = names.begin(); it != names.end(); ++it)
        setObjCoef(*it, coef);
}
Beispiel #5
0
void 
VrpModel::setModelData()
{
   CoinBigIndex i, j, numNonzeros = 0, numInt = 0;
   int size;
   
   int* varIndices = 0;
   double* varValues = 0;

   double* collb = new double [edgenum_];
   double* colub = new double [edgenum_];
   double* conUpper = new double[vertnum_];
   double* conLower = new double[vertnum_];
   double* objCoef = new double[edgenum_];

   for (i = 0; i < edgenum_; i++){
      objCoef[i] = edges_[i]->getObjCoef();
   }

   conLower[0] = conUpper[0] = 2*numroutes_;
   for (i = 1; i < vertnum_; i++){
      conUpper[i] = conLower[i] = 2.0;
   }

   char* colType = new char[edgenum_];
   
   // Get number of integer and number of nonzero for memory allocation.
   for (i = 0; i < edgenum_; ++i) {
       numNonzeros += edges_[i]->getSize();
       colType[i] = edges_[i]->getIntType();
   }

   int* indices = new int[numNonzeros];
   double* values = new double[numNonzeros];
   CoinBigIndex * start = new CoinBigIndex [edgenum_+1];
   
   // Get collb, colub, obj, and matrix from variables
   for (numInt = 0, numNonzeros = 0, i = 0; i < edgenum_; ++i) {
      collb[i] = edges_[i]->getLbHard();
      colub[i] = edges_[i]->getUbHard();

      start[i] = numNonzeros;
      varValues = edges_[i]->getValues();
      varIndices = edges_[i]->getIndices();

      size = edges_[i]->getSize();
      for (j = 0; j < size; ++j, ++numNonzeros){
	 indices[numNonzeros] = varIndices[j];
	 values[numNonzeros] = varValues[j];
      }
   }
   start[i] = numNonzeros;

   // Set input data
   setColMatrix(new CoinPackedMatrix(true, vertnum_, edgenum_, numNonzeros, 
				     values, indices, start, 0));
   
   setNumCons(vertnum_);
   setNumVars(edgenum_);

   setConLb(conLower);
   setConUb(conUpper);

   setVarLb(collb);
   setVarUb(colub);

   setObjCoef(objCoef);

   setColType(colType);    
   
   delete [] start;
   delete [] indices;
   delete [] values;
}