CPLEX Tutorial Handout

更新时间:2023-06-17 03:29:21 阅读: 评论:0

CPLEX Tutorial Handout
What Is ILOG CPLEX?
ILOG CPLEX is a tool for solving linear optimization problems, commonly referred to as Linear Programming (LP) problems, of the form:
Maximize (or Minimize) c1x1 + c2x2 +...+ c n x n
subject to  a11x1 + a12x2 +...+ a1n x n ~ b1
a21x1 + a22x2 +...+ a2n x n ~ b2
...
a m1x1 + a m2x2 +...+ a mn x n ~
b m
with the bounds  l1x1u1
...
l n x n u n
where ~ can be , , or =, and the upper bounds u i and lower bounds l i may be positive infinity, negative infinity, or any real number.
The elements of data you provide as input for this LP are:
Objective function coefficients  c1, c2, ... , c n
Constraint coefficients  a11, a21, ... , a n1
...
a m1, a m2, ..., a mn
Right-hand sides  b1, b2, ... , b m
Upper and lower bounds  u1, u2, ... , u n and l1, l2, ... , l n
The optimal solution that ILOG CPLEX computes and returns is: Variables x1, x2, ... , x n
ILOG CPLEX also can solve veral extensions to LP:
爱情的保质期
• Network Flow problems, a special ca of LP that CPLEX can solve much faster by exploiting the problem structure.
• Quadratic Programming (QP) problems, where the LP objective function is expanded to include quadratic terms.
• Mixed Integer Programming (MIP) problems, where any or all of the LP or QP variables are further restricted to take integer values in the optimal solution and where MIP itlf is extended to include
constructs like Special Ordered Sets (SOS) and mi-continuous variables.
ILOG CPLEX Components
CPLEX comes in three forms to meet a wide range of urs' needs:
• The CPLEX Interactive Optimizer is an executable program that can read a problem interactively or from files in certain standard formats, solve the problem, and deliver the solution interactively or into text files. The program consists of the on Windows platforms or cplex on UNIX
platforms.
英文爱情故事
• Concert Technology is a t of C++, Java, and class libraries offering an API that includes modeling facilities to allow the programmer to embed CPLEX optimizers in C++, Java, or
applications. The following table lists the files that contain the libraries.
Microsoft Windows  UNIX
C++  ilocplex.lib concert.lib libilocplex.a libconcert.a
Java  cplex.jar  cplex.jar
C#  ILOG.CPLEX.dll
ILOG.CONCERT.dll
• The CPLEX Callable Library is a C library that allows the programmer to embed ILOG CPLEX optimizers in applications written in C, Visual Basic, FORTRAN, or any other language that can call
C functions.The library is provided in files cplex.lib and cplex.dll on Windows platforms, and in
libcplex.a, libcplex.so, and libcplex.sl on UNIX platforms.
Solving an LP with ILOG CPLEX
The problem to be solved is:
Maximize  x1 + 2x2 + 3x3
subject to  -x1 + x2 + x3 20
x1 - 3x2 + x3 30
with the bounds  0 x1 40刘家拳
0 x2 +
0 x3 +
Using the Interactive Optimizer
The following sample is screen output from a CPLEX Interactive Optimizer ssion where the model of an example is entered and solved. CPLEX> indicates the CPLEX prompt, and text following this prompt is ur input.
Welcome to CPLEX Interactive Optimizer 9.0.0
with Simplex, Mixed Integer & Barrier Optimizers
Copyright (c) ILOG 1997-2003
CPLEX is a registered trademark of ILOG
Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.
CPLEX> enter example
Enter new problem ['end' on a parate line terminates]:
maximize x1 + 2 x2 + 3 x3
subject to -x1 + x2 + x3 <= 20
x1 - 3 x2 + x3 <=30
bounds
0 <= x1 <= 40
0 <= x2
0 <= x3
end
CPLEX> optimize
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time =    0.00 c.
Iteration log . . .
Iteration:    1  Dual infeasibility =            0.000000
葱白煮水Iteration:    2  Dual objective    =          202.500000
Dual simplex - Optimal:  Objective =  2.025*******e+002
Solution time =    0.01 c.  Iterations =2 (1)
CPLEX> display solution variables x1-x3
Variable Name          Solution Value
x1                          40.000000
x2                          17.500000
x3                          42.500000
CPLEX> quit
Concert Technology for Java Urs
• Creating a model
• Solving that model
• Querying results after solving
• Handling error conditions
ILOG Concert Technology allows your application to call ILOG CPLEX directly. This Java interface supplies a rich means for you to u Java objects to build your optimization model. The IloCplex class implements the ILOG Concert Technology interface for creating variables and constraints. It also provides functionality for solving Mathematical Programing (MP) problems and accessing solution information.
Compiling ILOG CPLEX Applications in ILOG Concert Technology
For this, you add the cplex.jar file to your classpath. This is most easily done by passing the command-line option to the Java compiler javac:
-classpath <path_to_cplex.jar>
In the java command line, the following should be added.
-Djava.library.path=<path_to_shared_library>
See the makefile utexas.edu/wangym .
The Anatomy of an ILOG Concert Technology Application
To u the ILOG CPLEX Java interfaces, you need to import the appropriate packages into your application. This is done with the lines:
t.*;
import ilog.cplex.*;
As for every Java application, an ILOG CPLEX application is implemented as a method of a class. In this discussion, the method will be the static main method. The first task is to create an IloCplex object. It is ud to create all the modeling objects needed to reprent the model. For example, an integer variable with bounds 0 and 10 is created by calling cplex.intVar(0, 10), where cplex is the IloCplex object.
Since Java error handling in ILOG CPLEX us exceptions, you should include the ILOG Concert Technology part of an application in a try/catch statement. All the exceptions thrown by any ILOG Concert Technology method are derived from IloException. Thus IloException should be caught in the catch statement.
In summary, here is the structure of a Java application that calls ILOG CPLEX:
t.*;
import ilog.cplex.*;
static public class Application {
static public main(String[] args) {
try {
跑步操音乐
IloCplex cplex =new IloCplex();
// create model and solve it
} catch (IloException e) {
}
}
}
描写竹子的词语Create the Model
The IloCplex object provides the functionality to create an optimization model that can be solved with IloCplex. The interface functions for doing so are defined by the ILOG Concert Technology interface IloModeler and its extension IloMPModeler. The interfaces define the constructor functions for modeling objects of the following types, which can be ud with IloCplex:
IloNumVar  modeling variables
IloRange  ranged constraints of the type lb <= expr <= ub
IloObjective  optimization objective
IloNumExpr  expression using variables
Modeling variables are reprented by objects implementing the IloNumVar interface defined by ILOG Concert Technology. Here is how to create three continuous variables, all with bounds 0 and 100: IloNumVar[] x = cplex.numVarArray(3, 0.0, 100.0);
There is a wealth of other functions for creating arrays or individual modeling variables. The documentation for IloModeler and IloMPModeler will give you the complete list.
Modeling variables are typically ud to build expressions, of type IloNumExpr, for u in constraints or the objective function of an optimization model. For example the expression:
x[0] + 2*x[1] + 3*x[2]
can be created like this:
IloNumExpr expr = cplex.sum(x[0], cplex.prod(2.0, x[1]),
cplex.prod(3.0, x[2]));
Another way of creating an object reprenting the same expression is to u an IloLinearNumExpr expression. Here is how:
IloLinearNumExpr expr = cplex.linearNumExpr();
expr.addTerm(1.0, x[0]);
expr.addTerm(2.0, x[1]);
不堪设想造句expr.addTerm(3.0, x[2]);
The advantage of using IloLinearNumExpr over the first way is that you can more easily build up your linear expression in a loop, which is what is typically needed in more complex applications. Interface IloLinearNumExpr is an extension of IloNumExpr, and thus can be ud anywhere an expression can be ud. As mentioned before, expressions can be ud to create constraints or an objective function for a model. Here is how to create a minimization objective for the above expression:
IloObjective obj =cplex.minimize(expr);
In addition to creating an objective, IloCplex must be instructed to u it in the model it solves. This is done by adding the objective to IloCplex via:
竹子的品质
cplex.add(obj);
Every modeling object that is to be ud in a model must be added to the IloCplex object. The variables need not be explicitly added as they are treated implicitly when ud in the expression of the objective. More generally, every modeling object that is referenced by another modeling object which itlf has been added to IloCplex, is implicitly added to IloCplex as well.
There is a shortcut notation for creating and adding the objective to IloCplex:
cplex.addMinimize(expr);
Since the objective is not otherwi accesd, it does not need to be stored in the variable obj.
Adding constraints to the model is just as easy. For example, the constraint
-x[0] + x[1] + x[2] <= 20.0
can be added by calling:
cplex.addLe(cplex.ative(x[0]), x[1], x[2]), 20);
Again, many methods are provided for adding other constraint types, including equality constraints, greater than or equal to constraints, and ranged constraints. Internally, they are all reprented as IloRange objects with appropriate choices of bounds, which is why all the methods return IloRange objects. Also, note that the expressions above could have been created in many different ways, including the u of IloLinearNumExpr. Solve the Model
IloCplex.solve()
IloCplex.solveRelaxed()
The returned value tells you what ILOG CPLEX found out about the model: whether it found the optimal solution or only a feasible solution, whether it proved the model to be unbounded or infeasible, or whether

本文发布于:2023-06-17 03:29:21,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1041921.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:竹子   爱情   音乐   保质期   跑步   词语   描写
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图