本文整理汇总了C++中IloModel::add方法的典型用法代码示例。如果您正苦于以下问题:C++ IloModel::add方法的具体用法?C++ IloModel::add怎么用?C++ IloModel::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IloModel
的用法示例。
在下文中一共展示了IloModel::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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
示例3: 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
示例4: createConstraintEnergy
int createConstraintEnergy(const Problem<double>& P, IloEnv& env, IloModel& model, IloNumVarArray& t, IloNumVarMatrix& b, IloNumVarMatrix& w){
for (int i=0;i<P.nbTask;++i){
IloExpr expr(env);
for (int e=0;e<2*P.nbTask-1;++e){
for (int q=0;q<P.A[i].Fi.nbPiece;++q)
model.add(P.A[i].Fi.F[q].f.a*b[i][e]+
P.A[i].Fi.F[q].f.c*(t[e+1]-t[e])>=w[i][e]);
expr+=w[i][e];
}
model.add(expr == P.W(i));
expr.end();
}
return 0;
}
示例5:
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
示例6: createConstraintTimeW
int createConstraintTimeW(const Problem<double>& P, IloModel& model,
IloNumVarArray& t, IloNumVarMatrix& x, IloNumVarMatrix& y, const std::vector<double>& M_te){
const int E=2*P.nbTask;
for (int i=0;i<P.nbTask;i++) {
for (int e=0;e<E;++e){
model.add(x[i][e]*P.r(i) <= t[e]);
model.add(t[e] <= x[i][e]*P.smax(i) +
(1-x[i][e])*M_te[e]);
model.add(P.d(i)*y[i][e] + (1-y[i][e])*M_te[e]>= t[e]);
model.add(t[e] >= y[i][e]*P.emin(i));
}
}
return 0;
}
示例7: 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));
}
示例8: IloMaximize
static void
populatebycolumn (IloModel model, IloNumVarArray x, IloRangeArray c)
{
IloEnv env = model.getEnv();
IloObjective obj = IloMaximize(env);
c.add(IloRange(env, -IloInfinity, 20.0));
c.add(IloRange(env, -IloInfinity, 30.0));
x.add(IloNumVar(obj(1.0) + c[0](-1.0) + c[1]( 1.0), 0.0, 40.0));
x.add(obj(2.0) + c[0]( 1.0) + c[1](-3.0));
x.add(obj(3.0) + c[0]( 1.0) + c[1]( 1.0));
model.add(obj);
model.add(c);
} // END populatebycolumn
示例9: 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();
}
}
示例10: createConstraintSepEvt
int createConstraintSepEvt(const Problem<double>& P,IloModel& model,
IloNumVarArray& t,const std::vector<std::vector<double>>& bound){
for (int e=0;e<2*P.nbTask-1;++e)
for (uint f=1;f<bound[e].size();++f)
model.add(t[e+f]-t[e]<=bound[e][f-1]);
return 0;
}
示例11:
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));
x.add(IloNumVar(env));
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);
} // END populatebyrow
示例12: createConstraintBmax
int createConstraintBmax(const Problem<double>&P, IloModel& model,
IloNumVarArray& t, IloNumVarMatrix& b){
for (int i=0;i<P.nbTask;i++){
for (int e=0;e<2*P.nbTask-1;e++)
model.add((t[e+1]-t[e])*P.bmax(i) >= b[i][e]);
}
return 0;
}
示例13:
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));
x.add(IloNumVar(env));
model.add(IloMaximize(env, x[0] + 2 * x[1] + 3 * x[2]
- 0.5 * (33*x[0]*x[0] + 22*x[1]*x[1] +
11*x[2]*x[2] - 12*x[0]*x[1] -
23*x[1]*x[2] ) ));
c.add( - x[0] + x[1] + x[2] <= 20);
c.add( x[0] - 3 * x[1] + x[2] <= 30);
model.add(c);
} // END populatebyrow
示例14: addConstraint_k_nodes_active
/*
* $\sum_{i > 0} v_i = k$. Ensure that exactly k nodes are active.
*/
static void addConstraint_k_nodes_active(IloEnv env, IloModel model, IloBoolVarArray vs, Instance& instance, u_int k)
{
IloExpr e_num_nodes(env);
for (u_int i = 1; i < instance.n_nodes; i++) {
e_num_nodes += vs[i];
}
model.add(k == e_num_nodes);
e_num_nodes.end();
}
示例15: addObjectiveFunction
/**
* Objective function:
* $\sum_{i, j} c_{ij} x_{ij}$
*/
static void addObjectiveFunction(IloEnv env, IloModel model, IloBoolVarArray xs, vector<Instance::Edge> edges, u_int n_edges)
{
IloExpr e_objective(env);
for (u_int m = 0; m < n_edges; m++) {
e_objective += xs[m] * edges[m].weight;
}
model.add(IloMinimize(env, e_objective));
e_objective.end();
}