本文整理汇总了C++中IloModel::getEnv方法的典型用法代码示例。如果您正苦于以下问题:C++ IloModel::getEnv方法的具体用法?C++ IloModel::getEnv怎么用?C++ IloModel::getEnv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IloModel
的用法示例。
在下文中一共展示了IloModel::getEnv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: profit_create_objective
void profit_create_objective(graph g, IloModel model, IloNumVarArray x, IloNumVarArray z, int **columns) {
IloNumExpr e(model.getEnv());
for(int i = 0; i < g->bidders; i++) {
e += z[i];
}
model.add(IloMaximize(model.getEnv(), e));
}
示例2: add_symmetric_inout_constraints
/* füge die symmetrsichen Constraints hinzu (sum_{j<i} x_{ij} = 2)
* Diese sind zwar auch Randfälle der SubtourEliminationConstraints, aber wenn man
* sie per Hand hinzufügt, beschleunigt das die Berechnungen extrem
* */
void CplexTSPSolver::add_symmetric_inout_constraints(IloModel model, IloNumVarArray x)
{
// wegen der Symmetrie ist nur das untere linke Dreieck mit
// variablen gefüllt. die inneren Schleifen gehen zeilen entlang
// und "reflektieren" an der Diagonalen.
// Die Kommentare "eingehend" und "ausgehend" stimmen so nicht,
// da tatsächlich symmetrie vorliegt, machen aber dennoch den Zweck
// deutlich
IloEnv env = model.getEnv();
for(int i=0; i<N; i++)
{
IloExpr expr(env);
// eingehende
for(int j=0; j<i; j++)
expr += x[i*N+j];
// ausgehende
for(int j=i+1; j<N; j++)
expr += x[j*N+i];
model.add(expr == 2);
expr.end();
}
}
示例3: Create2DArray
void Create2DArray(IloModel model, BoolVarMatrix m){
IloEnv env = model.getEnv();
for(int i = 0; i < m.getSize(); i++){
m[i]=IloBoolVarArray(env);
}
return;
}
示例4: init_symmetric_var
/* initialisiere N^2 Variablen und erstelle eine zu minimierende
* Strecken-Zielfunktion über die Distanzmatrix c
*
* eigentlich sind nur (N*N-N)/2 Variablen nötig, aber dafür müsste
* ich mir etwas schlaues zur Adressierung ausdenken (weil das untere linke
* Dreieck einer Matrix adressiert werden muss, ist das nicht trivial)
* Der Presolver scheint die überflüssigen Variablen allerdings
* direkt zu verwerfen, weshalb das nicht dringend ist.
* */
IloNumVarArray CplexTSPSolver::init_symmetric_var(IloModel model)
{
IloEnv env = model.getEnv();
// Edge Variables
IloNumVarArray x(env);
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
if(j<i)
x.add(IloNumVar(env, 0, 1, mip ? ILOINT : ILOFLOAT));
else
x.add(IloNumVar(env, 0, 0, ILOFLOAT)); // fülle oben rechts mit dummies
model.add(x);
// Cost Function
IloExpr expr(env);
// die folgenden Schleifen adressieren ein unteres linkes
// Dreieck in einer quadratischen Matrix
for(int i=0; i<N; i++)
for (int j=0; j<i; j++)
expr += c[i*N + j] * x[i*N + j];
model.add(IloMinimize(env, expr));
expr.end();
return x;
}
示例5: PopulateFromGraph
void PopulateFromGraph(IloModel model, IloNumVarArray s, IloRangeArray c){
IloEnv env = model.getEnv();
// Used n+1 for accomodating an extra variable
// For being able to write the objective function
for(int i = 0; i <= n; i++)
s.add(IloNumVar(env));
}
示例6: CreateStorageBindingConstraint
void CreateStorageBindingConstraint(IloModel model, BoolVar3DMatrix L, BoolVarMatrix M,
BoolVarMatrix X, BoolVar3DMatrix R, BoolVarMatrix Y,
IloRangeArray c){
IloEnv env = model.getEnv();
//The nested for-loops generate L[p][i][t]
//that is required to linearize equation 16
for(int p = 0; p < L.getSize(); p++){
for(int i = 0; i < n; i++){
for(int t = 0; t < T_MAX; t++){
L[p][i].add(IloBoolVar(env));
c.add(L[p][i][t] - M[p][i] - X[i][t] >= -1);
c.add(L[p][i][t] - M[p][i] - X[i][t] <= 0);
c.add(L[p][i][t] + M[p][i] - X[i][t] <= 1);
c.add(L[p][i][t] - M[p][i] + X[i][t] <= 1);
}
}
}
//Contructing the array R[p][e][t]
for(int p = 0; p < R.getSize(); p++){
for(int e = 0; e < E; e++){
for(int t = 0; t < T_MAX; t++){
R[p][e].add(IloBoolVar(env));
}
}
}
//Encoding the constraint eqn-15
for(int t = 0; t < T_MAX; t++){
IloExprArray sum(env);
for(int e = 0; e < E; e++){
sum.add(IloExpr(env));
for(int p = 0; p < n_m; p++){
sum[e] += R[p][e][t];
}
c.add(sum[e] - Y[e][t] == 0);
}
}
//Encoding the constraint eqn-21
for(int t = 0; t < T_MAX; t++){
IloExprArray sum1(env);
IloExprArray sum2(env);
for(int p = 0; p < n_m; p++){
sum1.add(IloExpr(env));
sum2.add(IloExpr(env));
for(int e = 0; e < E; e++)
sum1[p] += R[p][e][t];
for(int i = 0; i < n; i++)
sum2[p] += L[p][i][t];
c.add(sum1[p] - n_r*sum2[p] <= 0);
}
}
return;
}
示例7: obj
// This routine creates the master ILP (arc variables x and degree constraints).
//
// Modeling variables:
// forall (i,j) in A:
// x(i,j) = 1, if arc (i,j) is selected
// = 0, otherwise
//
// Objective:
// minimize sum((i,j) in A) c(i,j) * x(i,j)
//
// Degree constraints:
// forall i in V: sum((i,j) in delta+(i)) x(i,j) = 1
// forall i in V: sum((j,i) in delta-(i)) x(j,i) = 1
//
// Binary constraints on arc variables:
// forall (i,j) in A: x(i,j) in {0, 1}
//
void
createMasterILP(IloModel mod, Arcs x, IloNumArray2 arcCost)
{
IloInt i, j;
IloEnv env = mod.getEnv();
IloInt numNodes = x.getSize();
// Create variables x(i,j) for (i,j) in A
// For simplicity, also dummy variables x(i,i) are created.
// Those variables are fixed to 0 and do not partecipate to
// the constraints.
char varName[100];
for (i = 0; i < numNodes; ++i) {
x[i] = IloIntVarArray(env, numNodes, 0, 1);
x[i][i].setBounds(0, 0);
for (j = 0; j < numNodes; ++j) {
sprintf(varName, "x.%d.%d", (int) i, (int) j);
x[i][j].setName(varName);
}
mod.add(x[i]);
}
// Create objective function: minimize sum((i,j) in A ) c(i,j) * x(i,j)
IloExpr obj(env);
for (i = 0; i < numNodes; ++i) {
arcCost[i][i] = 0;
obj += IloScalProd(x[i], arcCost[i]);
}
mod.add(IloMinimize(env, obj));
obj.end();
// Add the out degree constraints.
// forall i in V: sum((i,j) in delta+(i)) x(i,j) = 1
for (i = 0; i < numNodes; ++i) {
IloExpr expr(env);
for (j = 0; j < i; ++j) expr += x[i][j];
for (j = i+1; j < numNodes; ++j) expr += x[i][j];
mod.add(expr == 1);
expr.end();
}
// Add the in degree constraints.
// forall i in V: sum((j,i) in delta-(i)) x(j,i) = 1
for (i = 0; i < numNodes; i++) {
IloExpr expr(env);
for (j = 0; j < i; j++) expr += x[j][i];
for (j = i+1; j < numNodes; j++) expr += x[j][i];
mod.add(expr == 1);
expr.end();
}
}// END createMasterILP
示例8: IloMaximize
static void
populatebynonzero (IloModel model, IloIntVarArray x, IloRangeArray c)
{
IloEnv env = model.getEnv();
IloObjective obj = IloMaximize(env);
int n, a;
scanf("%d", &n);
scanf("%d", &a);
//restrição
c.add(IloRange(env, -IloInfinity, a));
//variaveis
for(int i=0 ; i<n; i++){
x.add(IloIntVar(env, 0, 1));
}
/*x.add(IloIntVar(env, 0.0, 40.0));
x.add(IloIntVar(env));
x.add(IloIntVar(env));*/
/*obj.setLinearCoef(x[0], 1.0);
obj.setLinearCoef(x[1], 2.0);
obj.setLinearCoef(x[2], 3.0);*/
/*restricoes*/
for(int i=0 ; i<n; i++){
scanf("%d", &a);
c[0].setLinearCoef(x[i], a);
}
//objetivo
for(int i=0 ; i<n; i++){
scanf("%d", &a);
obj.setLinearCoef(x[i], a);
}
/*c[0].setLinearCoef(x[1], 1.0);
c[0].setLinearCoef(x[2], 1.0);
c[1].setLinearCoef(x[0], 1.0);
c[1].setLinearCoef(x[1], -3.0);
c[1].setLinearCoef(x[2], 1.0);*/
c[0].setName("c1");
for(int i=0; i<n; i++){
char tmp[10];
printf("x%d", i+1);
x[i].setName(tmp);
}
model.add(obj);
model.add(c);
} // END populatebynonzero
示例9: Create3DArray
void Create3DArray(IloModel model, BoolVar3DMatrix R, int size){
IloEnv env = model.getEnv();
for(int p = 0; p < R.getSize(); p++)
R[p] = BoolVarMatrix(env, E);
for(int p = 0; p < R.getSize(); p++){
for(int e = 0; e < size; e++)
R[p][e]=IloBoolVarArray(env);
}
return;
}
示例10: profit_constraints
ILOSTLBEGIN
IloRangeArray profit_constraints(graph g, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns) {
string s;
IloRangeArray c(model.getEnv());
c.add(assignment_ineq(g, model, x, columns));
for(int i = 0; i < g->bidders; i++) {
for(int edge = 0; edge < g->dbidder[i]; edge++) {
int k = g->b_adj[i][edge];
IloNumExpr e(model.getEnv());
for(int other_edge = 0; other_edge < g->dbidder[i]; other_edge++) {
int j = g->b_adj[i][other_edge];
e += g->adj[i][j]*x[columns[i][j]];
}
e += - z[i] + p[k];
c.add(e >= g->adj[i][k]);
s = "b_" + itos(i) + "," + itos(k);
c[c.getSize()-1].setName(s.c_str());
}
}
for(int i = 0; i < g->bidders; i++) {
IloNumExpr e(model.getEnv());
e += z[i];
for(int edge = 0; edge < g->dbidder[i]; edge++) {
int j = g->b_adj[i][edge];
e -= g->adj[i][j]*x[columns[i][j]];
}
c.add(e <= 0);
s = "c_" + itos(i);
c[c.getSize()-1].setName(s.c_str());
}
for(int i = 0; i < g->bidders; i++) {
for(int edge = 0; edge < g->dbidder[i]; edge++) {
int j = g->b_adj[i][edge];
IloNumExpr e(model.getEnv());
e += z[i] - p[j] - boundp(j)*x[columns[i][j]];
c.add(e >= - boundp(j));
s = "e_" + itos(i) + "," + itos(j);
c[c.getSize()-1].setName(s.c_str());
}
}
return c;
}
示例11: IloMaximize
static void
populatebynonzero(IloModel model, NumVarMatrix varOutput, NumVar3Matrix varHelp, Range3Matrix con)
{
IloEnv env = model.getEnv();
IloObjective obj = IloMaximize(env); //maximization function
for (int j = current; j < current + J; ++j)
{
for (int k = 0; k < K; ++k)
{
obj.setLinearCoef(varOutput[j][k], 1.0);//add all variables to objective function, factor 1
//constraint 0: express value of output objective variables
model.add(varOutput[j][k] + varHelp[j][k][2] - varHelp[j][k][3] == 0);
//constraint 1: Td2a>=+Td2b
model.add(varHelp[j][k][5] - varHelp[j][k][4] >= 0);
//constraint 2: Tj>=Td2a + Tdc + Tblow
model.add(varHelp[j][k][5] <= T[j] - Tdc - Tblow[j] - Tslack);
//constraint 3: Td2b = Tfa+Tfd
model.add(Tfd[k] == varHelp[j][k][4] - varHelp[j][k][3]);
//constraint 4: Td1a >= Td1b
model.add(0 <= varHelp[j][k][1] - varHelp[j][k][0]);
//constraint 5: Tfb >= Td1a+Tdf
model.add(Tdf[k] <= varHelp[j][k][2] - varHelp[j][k][1]);
//constraint 6: Td1b = T(j-a)+Tcd
model.add(T[j - a[k]] + Tcd == varHelp[j][k][0]);
//constraint 7: Td1a >= Td2b(j-b) + Tloss, 1
model.add(TlossD[k] <= varHelp[j][k][1] - varHelp[j - b[k]][k][4]);
//constraint 8: Tfb >= Tfa(j-1)+Tloss, 2
model.add(TlossF[k] <= varHelp[j][k][2] - varHelp[j - 1][k][3]);
//constraint 9: at least X s for every load
model.add(varOutput[j][k] >= TloadMin[k]);
}
//constraint 10: both spoons are picked up at same time at dropoff: Td2a,1 == Td2a,2
model.add(varHelp[j][1][5] == varHelp[j][0][5]);
}
model.add(obj);
}
示例12:
static void
populatebyrow (IloModel model, IloNumVarArray x, IloRangeArray c)
{
IloEnv env = model.getEnv();
x.add(IloNumVar(env, -1.0, 1.0));
x.add(IloNumVar(env, 0.0, 1.0));
model.add(IloMinimize(env, 0.5 * (-3*x[0]*x[0] - 3*x[1]*x[1] +
- 1*x[0]*x[1] ) ));
c.add( - x[0] + x[1] >= 0);
c.add( x[0] + x[1] >= 0);
model.add(c);
} // END populatebyrow
示例13: profit_create_vars
void profit_create_vars(graph g, IloModel model, IloNumVarArray x, IloNumVarArray p, IloNumVarArray z, int **columns) {
IloEnv env = model.getEnv();
string s;
assignment_vars(g, model, x, columns);
for(int j = 0; j < g->items; j++) {
s = "p_" + itos(j);
p.add(IloNumVar(env, 0.0, boundp(j), ILOFLOAT, s.c_str()));
// p.add(IloNumVar(env, lowerp(j), boundp(j), ILOFLOAT, s.c_str()));
}
for(int i = 0; i < g->bidders; i++) {
s = "z_" + itos(i);
z.add(IloNumVar(env, 0.0, boundu(i), ILOFLOAT, s.c_str()));
}
}
示例14: sosvar
static void
populatebyrow (IloModel model, IloNumVarArray x, IloRangeArray c)
{
IloEnv env = model.getEnv();
x.add(IloNumVar(env, 0.0, 40.0));
x.add(IloNumVar(env, 0.0, IloInfinity, ILOINT));
x.add(IloNumVar(env, 0.0, IloInfinity, ILOINT));
x.add(IloNumVar(env, 2.0, 3.0, ILOINT));
model.add(IloMaximize(env, x[0] + 2 * x[1] + 3 * x[2] + x[3]));
c.add( - x[0] + x[1] + x[2] + 10 * x[3] <= 20);
c.add( x[0] - 3 * x[1] + x[2] <= 30);
c.add( x[1] - 3.5* x[3] == 0);
model.add(c);
IloNumVarArray sosvar(env, 2);
IloNumArray sosval(env, 2);
sosvar[0] = x[2]; sosvar[1] = x[3];
sosval[0] = 25.0; sosval[1] = 18.0;
model.add(IloSOS1(model.getEnv(), sosvar, sosval));
} // END populatebyrow
示例15: 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);
}