当前位置: 首页>>代码示例>>C++>>正文


C++ IloCplex类代码示例

本文整理汇总了C++中IloCplex的典型用法代码示例。如果您正苦于以下问题:C++ IloCplex类的具体用法?C++ IloCplex怎么用?C++ IloCplex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IloCplex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addColumn

void addColumn(IloCplex subSolver, IloNumVarArray2 x, IloNumVarArray z, IloNumVarArray lambda,
	IloObjective rmpObj, IloRangeArray maintConEng, IloRangeArray removeMod,
	IloRangeArray convex, IloNumArray2 addXCol, IloNumArray addZCol, 
	const IloNumArray compCosts, const IloNumArray convexityCoef) {

	// loop counter
	IloInt t;		

	// counter for objective function coefficient for lambda
	// variable to be added.
	IloNum lambdaObjCoef = 0;

	// extract subproblem-optimal solution values
	// (into IloNumArrays addXCol (2d) and addZCol (1d)).

	// z values:
	subSolver.getValues(addZCol,z);

	//cout << endl << endl << "z = " << endl << addZCol << endl;
	//cin.get();

	// !!! OBS !!!
	// here we might want to save these z values some column pool's custom-nitted class
	// array. Or to be specific, we want to add the indexes for NON-ZERO-ENTRIES in addZCol
	// to our class that keep place of columns.
	// E.g., given variable lambda(m)_(q_m), we want to know in our own class object,
	// given (m)(q_m), the indexes of non-zeros in that Z column.
	


	// and for each t...
	for (t = 0; t < TIME_SPAN; t++) {

		// x values:
		subSolver.getValues(addXCol[t],x[t]);
		//cout << endl << endl << "x[t=" << t << "] =" << endl << addXCol[t] << endl;
	}
	//cin.get();

	// calculate objective function coefficient lambdaObjCoef
	for (t = 0; t < TIME_SPAN; t++) {

		// for each fixed t: scalar product of x[m]* vector and
		// component costs vector compCosts[m]:
		lambdaObjCoef += IloScalProd(addXCol[t],compCosts);

		// also clear the addXCol subarrays as soon as they
		// have been used
		addXCol[t].clear();
	}
			
	// now add this column and it's associated lambda variable to the RMP.
	lambda.add(IloNumVar(rmpObj(lambdaObjCoef) + maintConEng(addZCol) + 
		removeMod(addZCol) + convex(convexityCoef), 0.0, 1.0));

	// clear addZCol num array.
	addZCol.clear();

} // END of addColumn
开发者ID:dfrib,项目名称:thesis-bap-solver,代码行数:59,代码来源:columnGeneration.cpp

示例2: apply

 /** Apply the setting defined by this instance to <code>cplex</code>. */
 void apply(IloCplex cplex) const {
    switch (type) {
    case 'b': cplex.setParam(IloCplex::BoolParam(num), value.i != 0); break;
    case 'i': cplex.setParam(IloCplex::IntParam(num), value.i); break;
    case 'l': cplex.setParam(IloCplex::LongParam(num), value.l); break;
    case 'd': cplex.setParam(IloCplex::NumParam(num), value.d); break;
    }
 }
开发者ID:renvieir,项目名称:ioc,代码行数:9,代码来源:iloparmipopt.cpp

示例3: setCplexParam

int setCplexParam(IloCplex& cplex, IloEnv& env, int time_limit){
  //Set cplex parameter
  cplex.setParam(IloCplex::TiLim, time_limit);
  cplex.setParam(IloCplex::Threads, 2);
  cplex.setOut(env.getNullStream());
  cplex.setParam(IloCplex::PreLinear, 0);

  return 0;
}
开发者ID:sims2B,项目名称:Expe_these,代码行数:9,代码来源:startEndModel.cpp

示例4: displayResults

void displayResults(IloCplex& cplex,
                    IloNumVarArray inside,
                    IloNumVarArray outside) {
   cout << "cost: " << cplex.getObjValue() << endl;
   for(IloInt p = 0; p < nbProds; p++) {
      cout << "P" << p << endl;
      cout << "inside:  " << cplex.getValue(inside[p]) << endl;
      cout << "outside: " << cplex.getValue(outside[p]) << endl;
   }
}
开发者ID:mamadzebal,项目名称:server-load-balancing-in-sdn,代码行数:10,代码来源:inout1.cpp

示例5: PrintStorageBindingResult

void PrintStorageBindingResult(BoolVar3DMatrix R, map<int, string> start_time_rev, IloCplex cplex){
  double R_[n_m][E][T_MAX];
  for(int p = 0; p < n_m; p++){
    for(int e = 0; e < E; e++){
      for(int t = 0; t < T_MAX; t++){
        R_[p][e][t] = cplex.getValue(R[p][e][t]);
      }
    }
  }

  cout << "STORAGE BINDING RESULTS" << endl;
  for(int p = 0; p < n_m; p++){
    cout << "Module-" << p << " ";
    for(int e = 0; e < E; e++){
      for(int t = 0; t < T_MAX; t++){
        if(R_[p][e][t] == 1){
          cout << "(" <<start_time_rev[edges.at(e).first] << "-" << start_time_rev[edges.at(e).second] <<  ")" <<":" << t << " ";
        }
      }
    }
    cout << endl;
  }
  cout << endl;
  return;
}
开发者ID:trungda,项目名称:BioScheduling,代码行数:25,代码来源:Functions.cpp

示例6: print_values

static void print_values(IloCplex &cplex, const IloIntVarArray *xs)
{
	for (u_int i = 0; i < xs->getSize(); i++) {
		const int v = cplex.getValue((*xs)[i]);
		if (v == 0) {
			continue;
		}
		cout << (*xs)[i] << " = " << v << endl;
	}
}
开发者ID:schuay,项目名称:algorithmics,代码行数:10,代码来源:kMST_ILP.cpp

示例7: PrintSchedulingResult

void PrintSchedulingResult(IloNumVarArray s, map<int, string> start_time_rev, IloCplex cplex){
  vector<double> s_;
  for(int i = 0; i <= n; i++){
    s_.push_back(cplex.getValue(s[i]));
  }

  cout << "\nSCHEDULING RESULTS" << endl;
  map<string, int>::iterator it;
  for(it = start_time.begin(); it != start_time.end(); it++){
    cout << it->first << setw(4) << s_.at(it->second) << endl;
  }
  cout << endl;
  return;
}
开发者ID:trungda,项目名称:BioScheduling,代码行数:14,代码来源:Functions.cpp

示例8: ExtractSumK

DataNumMatrix DataVarBoolTriMatrix::ExtractSumK(IloEnv env, IloCplex cplex){
	DataNumMatrix res(env,this->n, this->m);

	for(int j = 1; j <= this->m; j++){
		for(int i = 1; i <= this->n; i++){
			Coordinate coord(i,j);
			res[coord] = 0;
			for(int l = 0; l < this->k; l++){
				res[coord] += cplex.getValue(this->get(i,j,l));

			}
		}
	}
	return res;
}
开发者ID:Razzis,项目名称:projet_ECMA,代码行数:15,代码来源:cplex_utils.cpp

示例9: ExtractSol

DataNumMatrix DataVarBoolMatrix::ExtractSol(IloEnv env, IloCplex cplex, Solution& sol){
	DataNumMatrix x_ij(env,sol.get_inst().get_n(),sol.get_inst().get_m());
	double Ca_x = 0;
	double Cp_x = 0;

	double CaHa_x = 0;
	double CpHp_x = 0;

	//int Cost = 0;


	for(int i = 1; i <= sol.get_inst().get_n(); i++){
		for(int j = 1; j <= sol.get_inst().get_m(); j++){
			Coordinate coord(i,j);
			//if(cplex.getValue(this->Matrix[i-1][j-1]) == 1)
			//	Cost++;
			Ca_x += sol.get_inst().get_grille(coord).get_Ca()*cplex.getValue(this->Matrix[i-1][j-1]);
			Cp_x += sol.get_inst().get_grille(coord).get_Cp()*cplex.getValue(this->Matrix[i-1][j-1]);

			CaHa_x += sol.get_inst().get_grille(coord).get_Ha()*sol.get_inst().get_grille(coord).get_Ca()*cplex.getValue(this->Matrix[i-1][j-1]);
			CpHp_x += sol.get_inst().get_grille(coord).get_Hp()*sol.get_inst().get_grille(coord).get_Cp()*cplex.getValue(this->Matrix[i-1][j-1]);

			sol.set_Choix_maille(coord) = cplex.getValue(this->Matrix[i-1][j-1]);
			x_ij[coord] = cplex.getValue(this->Matrix[i-1][j-1]);
		}
	}

	//sol.set_cost() = Cost;

	sol.set_Ha() = CaHa_x/Ca_x;
	sol.set_Hp() = CpHp_x/Cp_x;



	return x_ij;
}
开发者ID:Razzis,项目名称:projet_ECMA,代码行数:36,代码来源:cplex_utils.cpp

示例10: getComponents

// Set components[i] to the representative of the 
// component that contains the vertex i.
void getComponents (IloCplex &cplex,
					const IloArray <IloBoolVarArray>& solution,
					vector <int>& components) {
	// The size of the graph.
	int n = solution.getSize();

	// Each vertex is a component itself.
	for (int i = 0; i < n; i++)
		components[i] = i;
	
	// For each 1 in the incidence matrix,
	// join the components of these vertex.
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if (cplex.getValue (solution[i][j]) == 1)
				join (components, i, j);
}
开发者ID:jeffersonmoises,项目名称:pdpLU,代码行数:19,代码来源:util.cpp

示例11: modelToSol

int modelToSol(const Problem<double> &P,
	       Solution<double,double> &s,IloCplex& cplex,
	       IloNumVarArray& t,IloNumVarMatrix& x,
	       IloNumVarMatrix& y,IloNumVarMatrix& b){
  const int E=2*P.nbTask;
  for (int i=0;i<P.nbTask;++i){
    for (int e=0;e<E-1;++e){
      if (isEqual(cplex.getValue(x[i][e]),1.0)) s.st[i]=cplex.getValue(t[e]);
      if (isEqual(cplex.getValue(y[i][e]),1.0)) s.ft[i]=cplex.getValue(t[e]);
      if (!isEqual(cplex.getValue(t[e+1]-t[e]),0.0))
	s.b[i][e]=cplex.getValue(b[i][e])/(cplex.getValue(t[e+1]-t[e]));
      else
	s.b[i][e]=0.0;
    }
    if (isEqual(cplex.getValue(y[i][E-1]),1.0)) s.ft[i]=cplex.getValue(t[E-1]);
  }
  for (int e=0;e<E;++e)
    s.event.push_back(cplex.getValue(t[e]));
  return 0;
}
开发者ID:sims2B,项目名称:Expe_these,代码行数:20,代码来源:startEndModel.cpp

示例12: PrintMixingBindingResult

void PrintMixingBindingResult(BoolVarMatrix M, map<int, string> start_time_rev, IloCplex cplex){
  double M_[n_m][E];
  for(int i = 0; i < n_m; i++){
    for(int j = 0; j < n; j++)
      M_[i][j] = cplex.getValue(M[i][j]);
  }

  cout << "MIXING BINDING RESULTS" << endl;
  for(int i = 0; i < n_m; i++){
    cout << "Module-" << i << " ";
    for(int j = 0; j < n; j++){
      if(M_[i][j] == 1){
        cout << start_time_rev[j] << " ";
      }
    }
    cout << endl;
  }
  cout << endl;
  return;
}
开发者ID:trungda,项目名称:BioScheduling,代码行数:20,代码来源:Functions.cpp

示例13: profit_load

void profit_load(graph g, IloCplex cplex, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns, vector<int>& allocation, vector<double>& pricing) {
  IloNumVarArray startVar(model.getEnv());
  IloNumArray startVal(model.getEnv());
  for(int j = 0; j < g->items; j++) {
    if(boundp(j) > 0){
      startVar.add(p[j]);
      startVal.add(pricing[j]);
    }
  }
  for(int i = 0; i < g->bidders; i++) {
    for(int e = 0; e < g->dbidder[i]; e++) {
      int j = g->b_adj[i][e];
      startVar.add(x[columns[i][j]]);
      startVal.add(allocation[i] == j ? 1 : 0);
    }
  }
  for(int i = 0; i < g->bidders; i++) {
    if(boundu(i) > 0){
      startVar.add(z[i]);
      startVal.add(allocation[i] != -1 ? pricing[allocation[i]] : 0);
    }
  }
  cplex.addMIPStart(startVar, startVal);
}
开发者ID:awfeequdng,项目名称:envyfree-mip-models,代码行数:24,代码来源:profit.cpp

示例14: solveanddisplay

static void
solveanddisplay   (IloEnv env, IloCplex cplex, IloNumVarArray var,
                   IloRangeArray con)
{
      // Optimize the problem and obtain solution.
      if ( !cplex.solve() ) {
         env.error() << "Failed to optimize LP" << endl;
         throw(-1);
      }

      IloNumArray vals(env);
      env.out() << "Solution status = " << cplex.getStatus() << endl;
      env.out() << "Solution value  = " << cplex.getObjValue() << endl;
      cplex.getValues(vals, var);
      env.out() << "Values        = " << vals << endl;
      cplex.getSlacks(vals, con);
      env.out() << "Slacks        = " << vals << endl;
      cplex.getDuals(vals, con);
      env.out() << "Duals         = " << vals << endl;
      cplex.getReducedCosts(vals, var);
      env.out() << "Reduced Costs = " << vals << endl;

}  // END solveanddisplay
开发者ID:andreasmattas,项目名称:testcode,代码行数:23,代码来源:iloindefqpex1.cpp

示例15: getPath

// Finds the total path if there's no irregularity or an sub-path that 
// contains I and not I - n (Infeasible for family (5))
void getPath (const IloCplex& cplex,
			  const IloArray <IloBoolVarArray>& solution,
			  vector <int>& P,
			  vector<int>& VP,
			  int src,
			  const vector< Client > &precedences,
			  bool reverse) {
	// The depot always belongs to P
	P.push_back(src);

	// Mark the vertex alread visited on the path
	vector< bool > visited ( solution.getSize(), false );
	visited [src] = true;

	// Each iteration finds the next vertex on the path
	while ( P.size() < (size_t) solution.getSize() ) {

		// Finds the next vertex on the path (after src on the route)
		int v;
		for (v = ((reverse && (P.size() == 1)) ? 1 : 0); 
			 v < solution [src].getSize();
			 v++) { 
			if ((cplex.getValue (solution [src][v])) && 
				(visited [v] == false) )
				break;
		}
		// There must be such a vertex v (This solution is TSP feasible)
		//assert (v < solution.getSize());
		
		// Testing infeasibility (Searching in the precedence rules)
		for (size_t i = 0; i < precedences.size(); i++) {

			// If v is a location in this pair (rule)
			if (precedences[i].delivery == v || 
				precedences[i].pickup == v)  {

				// Adding v to the path and starting over with src == v;
				P.push_back(v); src = v; visited [v] = true;

				// Checking infeasibility 
				if (!reverse) {
					// If v is a delivery vertex and its pickup wasn't visited yet
					if ((precedences[i].delivery == v) && 
						(visited [ precedences[i].pickup ] == false)) {
						getCutComplement (visited, VP);
							return;
					}
				}
				else {
					// If v is a pickup vertex and its delivery wasn't visited yet
					if ((precedences[i].pickup == v) && 
						(visited [ precedences[i].delivery ] == false)) {
						getCutComplement (visited, VP);
						return;
					}
				}
				
				// v is feasible
				break;
			}
		}
		// Test other vertex at the while
	}
}
开发者ID:jeffersonmoises,项目名称:pdpLU,代码行数:66,代码来源:util.cpp


注:本文中的IloCplex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。