cplex中文教程 第五章
(完整word版)cplex翻译完全版

CPLEX 121. 简介................................................................. 3..2. 怎么用Cplex运行模型 (3)3. Cplex 概览........................................................... 3..3.1线性规划......................................................... 3.3.2二次约束规划....................................................4.3.3混合整数规划....................................................4.3.4可行松弛性...................................................... 5.3.5解池:产生和保持多解........................................... 5.4. GAMS 选项.......................................................... .9..5. Cplex选项总结 (10)5.1预处理和一般选项 (10)5.2单纯形法选项................................................... 1.25.3单纯形法的限制选项 (12)5.4单纯形法的容限选项 (13)5.5障碍特殊选项.................................................. 1.35.6筛选特殊选项................................................... 1.35.7混合整数规划选项 (13)5.8混合整数规划限制选项 (15)5.9混合整数规划解池选项 (16)5.10混合整数规划容许度选项....................................... 1.65.11输出选项...................................................... 1.75.12 GAMS/Cplex选项文件......................................... 1.76. 特殊备注 (18)6.1物理内存限制................................................... 1.86.2使用特殊有序集 (18)6.3使用半连续半整数变量 (19)6.4为求解MIP问题耗尽内存 (19)6.5不能证明整数最优 (20)6.6从混合整数规划的解开始 (20)6.7使用可行松弛性 (21)7. GAMS/ CPLE)日志文件 (22)8. CPLEX选项的详细说明 (25)1.简介GAMS/Cplex是一种用于GAMS (The General Algebraic Modeling System通用代数建模系统)的求解器,它使得用户可以把GAMS(通用代数建模系统的)的高级建模功能跟Cplex优化器的优势结合起来。
Rcplex 0.3-6 用户手册说明书

Package‘Rcplex’April6,2023Version0.3-6Title R Interface to CPLEXDescription R interface to CPLEX solvers for linear,quadratic,and(linear and quadratic)mixed inte-ger programs.Support for quadratically constrained programming is available.See thefile``IN-STALL''for details on how to install the Rcplex package in Linux/Unix-like and Windows sys-tems.Support for sparse matrices is provided by an S3-style class``sim-ple_triplet_matrix''from package slam and by objects from the Matrix package class hierarchy. LazyLoad yesDepends R(>=2.6.0),slamImports methodsEnhances MatrixSystemRequirements IBM ILOG CPLEX libraries and headersLicense LGPL(>=2.0)URL https:///projects/rcplexNeedsCompilation yesAuthor Hector Corrada Bravo[aut],Kurt Hornik[ctb](<https:///0000-0003-4198-9911>),Stefan Theussl[aut,cre](<https:///0000-0002-6523-4620>)Maintainer Stefan Theussl<****************************>Repository CRANDate/Publication2023-04-0611:40:11UTCR topics documented:Rcplex (2)Rcplex.close (6)Rcplex_solve_QCP (7)Index101Rcplex Solve optimization problem with CPLEXDescriptionInterface to CPLEX solvers for linear quadratic and(linear or quadratic)mixed-integer programs.The general statement of the problem ismin 12x Qx+c xs.t Ax≤blb≤x≤ubIf Q==NULL then the problem is linear,if any value of the vtype argument is"B"or"I"then the prob-lem is a mixed-integer program.The control argument is used to set CPLEX’s many parameters.See details.The objsense determines if the problem is a maximization or minimization problem.The sense argument is used to set the constraint directions.UsageRcplex(cvec,Amat,bvec,Qmat=NULL,lb=0,ub=Inf,control=list(),objsense=c("min","max"),sense="L",vtype=NULL,n=1)Argumentscvec The linear coefficient of the objective functionAmat The constraint matrix(requires ncol(Amat)==length(cvec))bvec The constraints right-hand side(requires length(bvec)==nrow(Amat))Qmat The quadratic coefficient of the objective function.If NULL the problem is lin-ear.If not NULL,it must be a symmetric positive semidefinite matrix of sizelength(cvec)by length(cvec).Default NULLlb Lower bound on the problem variables.If length(lb)==1then lb is the lowerbound of all variables.Otherwise,length(lb)==length(cvec).Set lb=-Infto have no lower bound.Default0.ub Upper bound on the problem variables.See lb for further details.Default Inf.control A list of CPLEX parameters.See*Details*objsense Either"max"or"min",determines the optimization direction.Default"min"sense The direction of the inequality in each constraint.If length(sense)==1then thesame value is taken for each constraint.Can be one of"L"(less than or equal),"G"(reater than or equal)or"E"(equal).Requires length(sense)==length(bvec).Default"L".vtype Determines the type of each problem variable.Can be one of"C"(continuous), "I"(integer)or"B"(binary).If length(vtype)==1the same value is taken forall variables.Otherwise,requires length(vtype)==length(ctype).Default"C".n Determines the maximal number of solutions the solver should return in case of an MIP with more than one solution at optimum.If CPLEX should searchfor"all"solutions then n has to be set to NA.In CPLEX this is also calledpopulating the solution pool.The parameters solnpoolagap,solnpoolgap,and solnpoolintensity influence the search for multiple solutions(see alsothe control argument below for details).Available from CPLEX11.0on.Rcplex()raises a warning if an older version of CPLEX is used and n>1.De-fault1.DetailsMatrices A and C may be sparse matrices from a class in the hierarchy defined by the Matrix pack-age.In that case,the internal casting functions are used to create the proper data structures to pass to CPLEX,which is similar to the column-major storage mode defined by the dgCMatrix-class defined by the Matrix package.We also provide a simple S3-style class for sparse matrices simple_triplet_matrix,as used in the relations package.Matrices A and C can be objects of this class.See the examples for example usage.simple_triplet_matrix objects MUST be in column-major order.The control argument can be used to set CPLEX’s many parameters,including the particular algorithm used for solving the given problem.See the ILOG CPLEX Parameters guide for further details.The following parameters are supported:trace:Turn CPLEX output on(1)or off(0).Default1.maxcalls:Number of calls to the CPLEX optimizer before license is released.Set to1to get a new license on every call to Rcplex.Can be any positive number.Default500.method:Algorithm to use(Default0):0:Automatic:CPLEX chooses algorithm automatically1:Primal Simplex2:Dual Simplex3:Network Simplex4:Barrierpreind:Turn presolver on(1)or off(0).Default1.aggind:Limit on the number of applications of the aggregator.Possible Values:-1(automatic),0 (do not use),any positive integeritlim:Maximum number of simplex iterations.Can be any nonnegative number.Default1e8.epagap:Absolute MIP optimality gap tolerance.Can be any nonnegative number.Default1e-6.epgap:Relative MIP optimality gap tolerance.Can be any nonnegative number.Default1e-4.tilim:Time limit in seconds of call to optimizer.Can be any nonnegative number.Default1e75.disjcuts:Indicator for disjunctive cuts used in MIP solver.Must be in-1:3.Default0(automatic).mipemphasis:Indicator for MIP solver emphasis.Must be in0:4.Default0(balance optimality and feasibility)cliques:Indicator for clique cuts in MIP solver.Must be in-1:2.Default0(automatic)nodesel:Node selection strategy in MIP solver.Must be in0:3.Default1(best-bound search).probe:Probe level in MPI solver.Must be-1:3.Default0(automatic)varsel:Variable selection strategy in MIP solver.Must be in-1:4.Default0(choose best method automatically).flowcovers:Indicator forflowcover cuts in MIP solver.Must be in-1:2.Default0(automatic).solnpoolagap:Sets an absolute tolerance on the objective value for the solutions in the solution pool.Can be any nonnegative real number.Ignored in versions<11.0of CPLEX.Default0 solnpoolgap:Sets a relative tolerance on the objective value for the solutions in the solution pool.Can be any nonnegative real number.Ignored in versions<11.0of CPLEX.Default0 solnpoolintensity:Controls the trade-off between the number of solutions generated for the solu-tion pool and the amount of time and memory consumed.Must be in0:4.Ignored in versions<11.0of CPLEX.Default0(automatic).round:Flag indicating if integer solutions for MIPs should be rounded before returning.In some cases,CPLEX returns slightly infeasible integer solutions.Setting this option to1ensures that the returned solution is integral by rounding.Default0(no rounding).ValueReturns a list with the following components,or,if n>1a list of length equal to the number of optimal solutions containing the following components for each solution:xopt Values of problem variables at optimum.obj Value of objective function at optimum.status Solution status.See CPLEX documentation for meaning of status codes.extra List with extra information about solution with componentsslack:Values of slack variables for inequality constraints.nodecnt:(IF MIP PROBLEM)Number of nodes in the search tree evaluatedlambda:(IF NOT MIP PROBLEM)Values of dual variables at optimumAuthor(s)Hector Corrada Bravo and Stefan TheusslReferencesIBM ILOG CPLEX Optimization Studio documentationSee AlsoRcplex.close,optimExamples##A linear program(this is lpex1.c in the CPLEX examples)cvec<-c(1,2,3)Amat<-matrix(c(-1,1,1,-1,3,-1),byrow=TRUE,nc=3)bvec<-c(20,-30)ub<-c(40,Inf,Inf)res<-Rcplex(cvec,Amat,bvec,ub=ub,objsense="max",sense=c( L , G )) print(res)##A linear program with random data##use the barrier methodn=20;m=25nnz<-trunc(.2*m*n)##entries in simple_triplet_matrix clas##*must*be in column major ordernnz<-sort(sample(m*n,nnz,replace=FALSE)-1)Amat<-simple_triplet_matrix(i=(nnz%%m)+1,j=trunc(nnz/m)+1,v=rnorm(nnz),nrow=m,ncol=n)x0<-runif(n)b<-as.matrix(Amat)%*%x0cvec<-rnorm(n)res<-Rcplex(cvec,Amat,b,sense= E ,control=list(method=4))print(res)##A quadratic problem(this is qpex1.c in the CPLEX examples)cvec<-c(1,2,3)Qmat<-matrix(c(-33,6,0,6,-22,11.5,0,11.5,-11),byrow=TRUE,nc=3)Amat<-matrix(c(-1,1,1,1,-3,1),byrow=TRUE,nc=3)bvec<-c(20,30)ub<-c(40,Inf,Inf)res<-Rcplex(cvec,Amat,bvec,Qmat,ub=ub,objsense="max")print(res)##A mixed integer linear program(mipex1.c in the CPLEX examples) cvec<-c(1,2,3,1)Amat<-matrix(c(-1,1,1,10,1,-3,1,0,0,1,0,-3.5),6Rcplex.close byrow=TRUE,nc=4)bvec<-c(20,30,0)lb<-c(0,0,0,2)ub<-c(40,Inf,Inf,3)vtype<-c(rep("C",3),"I")res<-Rcplex(cvec,Amat,bvec,lb=lb,ub=ub,sense=c("L","L","E"),objsense="max",vtype=vtype)print(res)##A mixed integer quadratic programcvec<-c(1,2,3,1)Qmat<-matrix(c(-33,6,0,0,6,-22,11.5,0,0,11.5,-11,0,0,0,0,0),byrow=TRUE,nc=4)Amat<-matrix(c(-1,1,1,10,1,-3,1,0,0,1,0,-3.5),byrow=TRUE,nc=4)bvec<-c(20,30,0)ub<-c(40,Inf,Inf,3)vtype<-c(rep("C",3),"I")res<-Rcplex(cvec,Amat,bvec,Qmat=Qmat,ub=ub,sense=c("L","L","E"),objsense="max",vtype=vtype)print(res)Rcplex.close()Rcplex.close Release CPLEX licenseDescriptionThis function releases the currently held CPLEX license.UsageRcplex.close()Author(s)Hector Corrada BravoSee AlsoRcplexRcplex_solve_QCP Solve quadratically constrained optimization problem with CPLEXDescriptionInterface to CPLEX solvers for quadratically constrained linear,quadratic,and mixed-integer pro-grams.The general statement of the problem ismin 12x Qx+c xs.t Ax≤band a i x+x Q i x≤r i fori=1,...,qlb≤x≤ubIf Q==NULL then the problem is linear,if any value of the vtype argument is"B"or"I"then the prob-lem is a mixed-integer program.The control argument is used to set CPLEX’s many parameters.See details.The objsense determines if the problem is a maximization or minimization problem.The sense argument is used to set the constraint directions.UsageRcplex_solve_QCP(cvec,Amat,bvec,Qmat=NULL,QC,lb=0,ub=Inf,sense="L",objsense=c("min","max"),vtype =NULL,n=1,control=list())Argumentscvec The linear coefficient of the objective functionAmat The constraint matrix(requires ncol(Amat)==length(cvec))bvec The constraints right-hand side(requires length(bvec)==nrow(Amat))Qmat The quadratic coefficient of the objective function.If NULL the problem is lin-ear.If not NULL,it must be a symmetric positive semidefinite matrix of sizelength(cvec)by length(cvec).Default NULLQC a list with three elements:QC,dir,and b.The element QC is a list with the quadratic part Q,a matrix,and the linear part of the constraint L,a numeric(currently nonzero values are not supported).dir has the same meaning asargument sense and b as bvec.lb Lower bound on the problem variables.If length(lb)==1then lb is the lower bound of all variables.Otherwise,length(lb)==length(cvec).Set lb=-Infto have no lower bound.Default0.ub Upper bound on the problem variables.See lb for further details.Default Inf.control A list of CPLEX parameters.See*Details*objsense Either"max"or"min",determines the optimization direction.Default"min"sense The direction of the inequality in each constraint.If length(sense)==1then thesame value is taken for each constraint.Can be one of"L"(less than or equal),"G"(reater than or equal)or"E"(equal).Requires length(sense)==length(bvec).Default"L".vtype Determines the type of each problem variable.Can be one of"C"(continuous),"I"(integer)or"B"(binary).If length(vtype)==1the same value is taken forall variables.Otherwise,requires length(vtype)==length(ctype).Default"C".n Determines the maximal number of solutions the solver should return in caseof an MIP with more than one solution at optimum.If CPLEX should searchfor"all"solutions then n has to be set to NA.In CPLEX this is also calledpopulating the solution pool.The parameters solnpoolagap,solnpoolgap,and solnpoolintensity influence the search for multiple solutions(see alsothe control argument below for details).Available from CPLEX11.0on.Rcplex()raises a warning if an older version of CPLEX is used and n>1.De-fault1.DetailsSee function link[Rcplex]{Rcplex}()for more information about sparse matrix representation and control arguments.ValueReturns a list with the following components,or,if n>1a list of length equal to the number of optimal solutions containing the following components for each solution:xopt Values of problem variables at optimum.obj Value of objective function at optimum.status Solution status.See CPLEX documentation for meaning of status codes.extra List with extra information about solution with componentsslack:Values of slack variables for inequality constraints.nodecnt:(IF MIP PROBLEM)Number of nodes in the search tree evaluatedlambda:(IF NOT MIP PROBLEM)Values of dual variables at optimumAuthor(s)Hector Corrada Bravo and Stefan TheusslReferencesIBM ILOG CPLEX Optimization Studio documentationSee AlsoRcplex.close,optimExamples##objective functionc<-c(1,2,3)Q<-matrix(c(-33,6,0,6,-22,11.5,0,11.5,-11),nrow=3)##constraints##linear partA<-matrix(c(-1,1,1,-3,1,1),nrow=2)dir<-c("L","L")b<-c(20,30)##quadratic partQC<-list(QC=list(Q=list(diag(1,nrow=3)),L=NULL),dir="L",b=1)##boundsub<-c(40,Inf,Inf)##solveres<-Rcplex_solve_QCP(c,A,b,Q,ub=ub,QC=QC,sense=dir,objsense="max") print(res)##solve MIQCPres<-Rcplex_solve_QCP(c,A,b,Q,ub=ub,QC=QC,sense=dir,objsense="max",vtype=c("C","I","C")) ##quadratic and linear partQC<-list(QC=list(Q=list(diag(1,nrow=3)),L=list(c(3,4,-3))),dir="L",b=1)##solveres<-Rcplex_solve_QCP(c,A,b,Q,ub=ub,QC=QC,sense=dir,objsense="max") print(res)Rcplex.close()Index∗optimizeRcplex,2Rcplex_solve_QCP,7∗utilitiesRcplex.close,6optim,4,8Rcplex,2,6Rcplex.close,4,6,8Rcplex_solve_QCP,710。
『实践』Yalmip+Ipopt+Cplex使用手册(文末附程序)

『实践』Yalmip+Ipopt+Cplex使⽤⼿册(⽂末附程序)Yalmip+Ipopt+Cplex使⽤⼿册(⽂末附程序)1.软件版本Cplex 12.6.2,Matlab R2014a, 3.12.9,2.Cplex添加⽅法破解版下载地址:其中community-edition可以免费试⽤,但最多只能计算1000个变量或1000个约束条件的优化问题。
点击安装,安装步骤默认操作即可。
点击Matlab中的,点击,找到路径并将其添加,最后点击即可。
然后在Matlab命令⾏窗⼝输⼊,出现帮助⽂档,代表添加成功。
3.Ipopt添加⽅法需要的组件:VC_redist.x64和ww_ifort_redist_intel64_2017.0.109.msi链接2:在打开的界⾯中选择图1-1即可。
图1Ipopt下载地址:(最新版本3.12.9)Ipopt下载链接:链接:https:///s/1tWBRJ7syW-WctcL1LkB06w 密码:1n3m (以前的版本3.12.6)下载下来后解压缩,打开⽂件,⽬录如下图1-2。
图2打开MATLAB,设置路径-》添加并包含⼦⽂件夹-》选择Ipopt路径-》保存。
见下图1-3。
图3右键运⾏图2中的opti_Install。
出现提⽰让你安装optiMEXFiles_mexw64_2_27,回车⼏下,弹出窗⼝,找到optiMEXFiles_mexw64_2_27(不需要⾃⼰⼿动解压)选中即可。
VC_redist.x64和ww_ifort_redist_intel64_2017.0.109.msi ,这两个组件⾃⼰⼿动安装,注意版本即可。
注意下图中框框中的组件我已经安装好了,如果没有安装,是会有提⽰的。
IPOPT 3.12.94.Yalmip添加⽅法下载地址:https://yalmip.github.io/(最新版本)下载链接:/s/1eRBhRlK 密码:dv4o(之前版本)将下载的⽂件解压,设置路径-》添加并包含⼦⽂件夹-》选择Yalmip路径-》保存。
Cplex学习笔记

Cplex学习笔记thedualsimplexmethodisthefirstchoiceforoptimizingalinearprogrammingproblem,esp eciallyforprimal-degenerateproblemswithlittlevariabilityintherighthandsidecoefficientsbutsignif icantvariabilityinthecostcoefficients.PrimarSimpleXOptimizer有时会更好地解决变量数量显著增加约束数量的问题,或者解决成本系数中几乎没有变化的问题。
六百五十四networkoptimizermayhaveapositiveimpactonperformanceofnetworkstructure 屏障优化因子和方法在大型稀疏问题上是有效的siftingwasdevelopedtoexploitthecharacteristicsofmodelswithlargeaspectratios(th atis,alargeratioofthenumberofcolumnstothenumberofrows).并行优化器多线程计算机平台简言之:原始变量多于约束对偶右停左变,边界大型稀疏阵筛选行列数差大。
要保存基本安全文件:libraryroutinecpxmbasewrite,afterthecalltotheoptimizer.然后从该文件中更新更新基础:cpxreadcopybase.如果解决问题所需的迭代次数与不足的次数大致相同,那么你做得很好。
如果迭代次数比行数(或更多)大三倍,则完全有可能通过改变为UALSimplexOptimizer或Primind implexOptimizer设置定价算法的参数DPRI来提高性能ifyouobservethatyourproblemhasdifficultystayingfeasibleduringitssolution,theny oushouldconsideranalternativescalingmethod.scaindparametersettingsforscalingme thods斯坎德价值意义-1noscaling0平衡缩放(默认)1缩放缩放671cplex学习手册STL标准模板库简称STL,即标准模板库。
CPLEX中文教程(第七章)

CPLEX中文教程(第七章)第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用(一)公交乘务排班优化问题概述公交乘务排班问题属活动资源的优化利用问题。
一般是根据给定的乘务任务、乘务规则等条件,考虑一定的优化目标,对乘务员(组)的出乘时间、地点,担当的乘务任务、时刻,退乘时间、地点等做出具体安排,以确保一定周期内的所有乘务任务被执行。
第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用公交乘务排班问题的基本元素和各元素的基本属性如下:1)公交线路:具有出发站、出发时刻、到达站、到达时刻、中途停站等基本属性;2)乘务员类型(组):包括司机、售票员等属性;3)乘务规则:包括间休时间、工作时间、休息时间、乘务周期、月工时等乘务值乘规则。
4)目标函数:乘务成本最小、需要的乘务员数量最少等。
5)约束条件:乘务员的工作时间必须满足乘务规则;每个线路、每个班次都必须有乘务员值乘;乘务员劳动负衡均衡等约束条件。
第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用例1.下面是某条线路的基本情况:1、该线路的开收班时间:冬令(12月~3月):6:20~18:10,夏令(4月~11月):6:15~18:202、该线路的司机人数:15人3、该线路排班间隔:平时:8~10分钟/班;上下班高峰(6:00~8:30,11:30~13:30,16:30~18:00):4~8分钟/班节假日:5~10分钟/班4、该线路的运行时间:正常:80~85分钟/班高峰:100~120分钟/班规定:(1)司机每天上班时间不超过8小时;(2)司机连续开车不得超过4小时;(3)每名司机至少每月完成120班次。
问题一:针对五月份的节假日和非节假日,分别求出每日最少班次总数;问题二:阐述你对上述规定的理解,并根据你的理解建立适当的数学模型,合理地设计五月份该线路的司机排班方案。
第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用(二)模型建立与求解1、问题一:数学模型的建立(1)假设将非节假日一天的工作时间分为n个时段6minZ=i=1某ikk某imiQii1i1kkS.T.某imimkQii1i18mi104mi8k1,2,3,4,5,6.k1,2,3,4,5,6.i2,4,6.i1,3,5.Qi——第i个时段的时长,i=1,2…,nmi——表示发车间隔;某i——表示发车班次用第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用问题一:1、数学模型的建立(2)若节假日,用Q表示节假日一天的工作时长,发车间隔用m表示,则例1中节假日最少班次的数学公式为:QminZ=,m5≤m≤10.第七章:IBMILOGCPLE某在公交乘务排班优第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用问题一的模型文件(续):某["T1"]某m["T1"]+某["T2"]某m["T2"]+(某["T3"]-1)某m["T3"]<=Q["T1"]+Q["T2"]+Q["T3"];Q["T1"]+Q["T2"]+Q["T3"]<=某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"];某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+(某["T4"]1)某m["T4"]<=Q["T1"]+Q["T2"]+Q["T3"]+Q["T4"];Q["T1"]+Q["T2"]+Q["T3"] +Q["T4"]<=某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+某["T4"]某m["T4"];某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+某["T4"]某m["T4"]+(某["T5"]1)某m["T5"]<=Q["T1"]+Q["T2"]+Q["T3"]+Q["T4"]+Q["T5"];Q["T1"]+Q["T2"] +Q["T3"]+Q["T4"]+Q["T5"]<=某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+某["T4"]某m["T4"]+某["T5"]某m["T5"];某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+某["T4"]某m["T4"]+某["T5"]某m["T5"]+(某["T6"]1)某m["T6"]<=Q["T1"]+Q["T2"]+Q["T3"]+Q["T4"]+Q["T5"]+Q["T6"];Q["T1"] +Q["T2"]+Q["T3"]+Q["T4"]+Q["T5"]+Q["T6"]<=某["T1"]某m["T1"]+某["T2"]某m["T2"]+某["T3"]某m["T3"]+某["T4"]某m["T4"]+某["T5"]某m["T5"]+某["T6"]某m["T6"];}第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用求解结果:高峰期(6:158:30)发车时间班次1234567891011121314151617平时(8:3011:30)发车时间08:3108:4108:5109:0109:1109:2109:3109:4109:5110:0110:1110:2110: 3110:4110:5111:0111:1111:21班次181920222223242526272829303132333435高峰期(11:3013:30)发车时间11:3111:3911:4711:5512:0312:1112:1912:2712:3512:4312:5112:5913: 0713:1513:23班次363738394041424344454647484950平时(13:3016:30)发车时间13:3113:4113:5114:0114:1114:2114:3114:4114:5115:0115:1115:2115: 3115:4115:5116:0116:1116:21班次515253545556575859606162636465666768高峰期(16:3018:00)发车时间16:3116:3916:4716:5517:0317:1117:1917:2717:3517:4317:5117:59班次697071727374757677787980平时(18:0018:20)发车时间18:0718:17班次8182//olution(optimal)withobjective82某=[17181518122]06:1506:2306:3106:3906:4706:5507:0307:1107:19据此,得到该线路非节假日的最少班次排班如右:07:2707:3507:4307:5107:5908:0708:1508:23第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用求解结果:发车时间班次123456789101112发车时间08:1508:2508:3508:4508:5509:0509:1509:2509:3509:4509:5510:05班次131415161718192022222324时间(6:20-18:10)发车时间10:1510:2510:3510:4510:5511:0511:1511:2511:3511:4511:5512:05班次252627282930313233343536发车时间12:1512:2512:3512:4512:5513:0513:1513:2513:3513:4513:5514:05班次373839404142434445464748发车时间14:1514:2514:3514:4514:5515:0515:1515:2515:3515:4515:5516:05班次495051525354555657585960发车时间16:1516:2516:3516:4516:5517:0517:1517:2517:3517:4517:5518:0518:15班次61626364656667686970717273节假日的最少班次排班如右:06:1506:2506:3506:4506:5507:0507:1507:2507:3507:4507:5508:05第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用问题二:1、数学模型的建立(1)非节假日目标函数:min约束条件:某jj119式中:ai——表示非节假日一天内第i个司机工作的高峰班次数bi——表示非节假日一天内第i个司机工作的非高峰班次数某j——表示司机排班情况(aij119j119某j)44(bi某j)38第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用司机排班情况第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用模型编码:{tring}Categorie={"C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13","C14","C15","C16","C17","C18","C19"};inta [Categorie]=[0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,4,4];intb[Categor ie]=[1,2,3,4,5,0,1,2,3,4,0,1,2,3,0,1,2,0,1];dvarint+某[Categorie]in0..50;minimizeum(oinCategorie)某[o];ubjectto{um(oinCategorie)a[o]某某[o]==44;um(oinCategorie)b[o]某某[o]==38;}第七章:IBMILOGCPLE某在公交乘务排班优化问题中的应用求解结果://olution(optimal)withobjective17某=[01005000000000000011]该结果给出了一天需要的最少司机人数为17人,同时给出了一个可行的排班方案,即17位司机中,有1位采用第2种排班情况,有5位采用第5种排班情况,有11位采用第19种排班情况。
cplex中文教程 第四章

第四章IBM ILOG CPLEX在高速铁路列车运行图编制中的应用 数据文件:
例1:假定2列中速列车,1列高速列车,5个车站。
数据文件编码为:
nctrain=2; nhtrain=1; nstation=5; a=[4,4,4,4,4]; d=[3,3,3,3,3]; r=[[24,8,20,38],[24,8,20,38],[16,6,13,25]]; b=[[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]; c=[[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]]; w=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]; M=100000000; e=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]];
停站时间约束
yik xi变
k 2Sik ik qij (i 1, 2, j
, N ; k 2,3,
, m 1)
, N ; k 2,3,
, m 1)
第四章IBM ILOG CPLEX在高速铁路列车运行图编制中的应用
第四章IBM ILOG CPLEX在高速铁路列车运行图编制中的应用 例2求解结果:
// solution (optimal) with objective 1606 x = [[0 17 39 59 101 129 152] y = [[0 17 40 59 102 129 152] [0 21 43 63 106 135 159] [3 22 43 65 106 136 159] [0 26 54 79 131 164 191] [6 26 55 81 132 164 191] [0 59 81 101 143 171 194] [42 59 82 101 144 171 194] [0 63 85 105 147 174 197] [45 64 85 107 147 174 197] [0 66 88 108 151 180 204] [48 67 88 110 151 181 204] [0 73 102 127 180 215 243] [51 74 103 129 181 216 243] [0 110 131 151 194 223 246] [94 110 131 153 194 223 246] [0 114 136 156 198 226 249] [97 114 137 156 199 226 249] [0 117 140 162 206 234 257]] [100 117 141 164 207 234 257]]
CPLEX Tutorial Handout

CPLEX Tutorial HandoutWhat 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 nsubject to a11x1 + a12x2 +...+ a1n x n ~ b1a21x1 + a22x2 +...+ a2n x n ~ b2...a m1x1 + a m2x2 +...+ a mn x n ~b mwith these bounds l1x1u1...l n x n u nwhere ~ 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 nConstraint coefficients a11, a21, ... , a n1...a m1, a m2, ..., a mnRight-hand sides b1, b2, ... , b mUpper and lower bounds u1, u2, ... , u n and l1, l2, ... , l nThe optimal solution that ILOG CPLEX computes and returns is: Variables x1, x2, ... , x nILOG CPLEX also can solve several extensions to LP:• Network Flow problems, a special case 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 itself is extended to includeconstructs like Special Ordered Sets (SOS) and semi-continuous variables.ILOG CPLEX ComponentsCPLEX comes in three forms to meet a wide range of users' 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 file cplex.exe on Windows platforms or cplex on UNIXplatforms.• Concert Technology is a set of C++, Java, and .NET class libraries offering an API that includes modeling facilities to allow the programmer to embed CPLEX optimizers in C++, Java, or .NETapplications. The following table lists the files that contain the libraries.Microsoft Windows UNIXC++ ilocplex.lib concert.lib libilocplex.a libconcert.aJava cplex.jar cplex.jarC#.NET ILOG.CPLEX.dllILOG.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 callC functions.The library is provided in files cplex.lib and cplex.dll on Windows platforms, and inlibcplex.a, libcplex.so, and libcplex.sl on UNIX platforms.Solving an LP with ILOG CPLEXThe problem to be solved is:Maximize x1 + 2x2 + 3x3subject to -x1 + x2 + x3 20x1 - 3x2 + x3 30with these bounds 0 x1 400 x2 +0 x3 +Using the Interactive OptimizerThe following sample is screen output from a CPLEX Interactive Optimizer session where the model of an example is entered and solved. CPLEX> indicates the CPLEX prompt, and text following this prompt is user input.Welcome to CPLEX Interactive Optimizer 9.0.0with Simplex, Mixed Integer & Barrier OptimizersCopyright (c) ILOG 1997-2003CPLEX is a registered trademark of ILOGType 'help' for a list of available commands.Type 'help' followed by a command name for moreinformation on commands.CPLEX> enter exampleEnter new problem ['end' on a separate line terminates]:maximize x1 + 2 x2 + 3 x3subject to -x1 + x2 + x3 <= 20x1 - 3 x2 + x3 <=30bounds0 <= x1 <= 400 <= x20 <= x3endCPLEX> optimizeTried aggregator 1 time.No LP presolve or aggregator reductions.Presolve time = 0.00 sec.Iteration log . . .Iteration: 1 Dual infeasibility = 0.000000Iteration: 2 Dual objective = 202.500000Dual simplex - Optimal: Objective = 2.025*******e+002Solution time = 0.01 sec. Iterations =2 (1)CPLEX> display solution variables x1-x3Variable Name Solution Valuex1 40.000000x2 17.500000x3 42.500000CPLEX> quitConcert Technology for Java Users• Creating a model• Solving that model• Querying results after solving• Handling error conditionsILOG Concert Technology allows your application to call ILOG CPLEX directly. This Java interface supplies a rich means for you to use 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 TechnologyFor 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 at /wangym .The Anatomy of an ILOG Concert Technology ApplicationTo use the ILOG CPLEX Java interfaces, you need to import the appropriate packages into your application. This is done with the lines:import ilog.concert.*;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 used to create all the modeling objects needed to represent 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 uses 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:import ilog.concert.*;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) {System.err.println("Concert exception caught: " + e);}}}Create the ModelThe 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. These interfaces define the constructor functions for modeling objects of the following types, which can be used with IloCplex:IloNumVar modeling variablesIloRange ranged constraints of the type lb <= expr <= ubIloObjective optimization objectiveIloNumExpr expression using variablesModeling variables are represented 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 used to build expressions, of type IloNumExpr, for use 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 representing the same expression is to use 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 used anywhere an expression can be used. As mentioned before, expressions can be used 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 use 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 used in a model must be added to the IloCplex object. The variables need not be explicitly added as they are treated implicitly when used in the expression of the objective. More generally, every modeling object that is referenced by another modeling object which itself 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 otherwise accessed, 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.0can be added by calling:cplex.addLe(cplex.sum(cplex.negative(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 represented as IloRange objects with appropriate choices of bounds, which is why all these methods return IloRange objects. Also, note that the expressions above could have been created in many different ways, including the use of IloLinearNumExpr. Solve the ModelIloCplex.solve()IloCplex.solveRelaxed()IloCplex.getStatus.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 whethernothing at all has been determined at this point. Even more detailed information about the termination of the solver call is available through the method IloCplex.getCplexStatus.Query the ResultsIf the solve method succeeded in finding a solution, you will then want to access that solution. The objective value of that solution can be queried using a statement like this:double objval = cplex.getObjValue();Similarly, solution values for all the variables in the array x can be queried by calling:double[] xval =cplex.getValues(x);More solution information can be queried from IloCplex, including slacks and, depending on the algorithm that was applied for solving the model, duals, reduced cost information, and basis information.Building and Solving a Small LP Model in JavaThe example LPex1.java, part of the standard distribution of ILOG CPLEX, is a program that builds a specific small LP model and then solves it. This example follows the general structure found in many ILOG CPLEX Concert Technology applications, and demonstrates three main ways to construct a model: • Modeling by Rows;• Modeling by Columns;Example LPex1.javaMaximize x1 + 2x2 + 3x3subject to -x1 + x2 + x3 20x1 - 3x2 + x3 30with these bounds 0 x1 400 x2 +0 x3 +Program for building and solving the exampleimport ilog.concert.*;import ilog.cplex.*;public class Example {public static void main(String[] args) {try {IloCplex cplex =new IloCplex();double[] lb ={0.0, 0.0, 0.0};double[] ub ={40.0, Double.MAX_VALUE, Double.MAX_VALUE};IloNumVar[] x =cplex.numVarArray(3, lb, ub);double[] objvals ={1.0, 2.0, 3.0};cplex.addMaximize(cplex.scalProd(x, objvals));cplex.addLe(cplex.sum(cplex.prod(-1.0, x[0]),cplex.prod( 1.0, x[1]),cplex.prod( 1.0, x[2])), 20.0);cplex.addLe(cplex.sum(cplex.prod( 1.0, x[0]),cplex.prod(-3.0, x[1]),cplex.prod( 1.0, x[2])), 30.0);if ( cplex.solve() ) {cplex.out().println("Solution status =" + cplex.getStatus());cplex.out().println("Solution value =" + cplex.getObjValue()); double[] val =cplex.getValues(x);int ncols =cplex.getNcols();for (int j =0; j < ncols; ++j)cplex.out().println("Column: " + j + " Value =" + val[j]);}cplex.end();}catch (IloException e) {System.err.println("Concert exception '" + e + "' caught");}}}Compile and run% javac example.java% java exampleor if you use makefile% makeComplete Code of LPex1.java// ----------------------------------------------------------------------- // File: examples/src/LPex1.java// Version 9.0// ----------------------------------------------------------------------- // Copyright (C) 2001-2003 by ILOG.// All Rights Reserved.// Permission is expressly granted to use this example in the// course of developing applications that use ILOG products.// ----------------------------------------------------------------------- //// LPex1.java - Entering and optimizing an LP problem//// Demonstrates different methods for creating a problem. The user has to // choose the method on the command line://// java LPex1 -r generates the problem by adding constraints// java LPex1 -c generates the problem by adding variables// java LPex1 -n generates the problem by adding expressions//import ilog.concert.*;import ilog.cplex.*;public class LPex1 {static void usage() {System.out.println("usage: LPex1 <option>");System.out.println("options: -r build model row by row");System.out.println("options: -c build model column by column");System.out.println("options: -n build model nonzero by nonzero");}public static void main(String[] args) {if ( args.length != 1 || args[0].charAt(0) != `-' ) {usage();return;}try {// Create the modeler/solver objectIloCplex cplex =new IloCplex();IloNumVar[][] var =new IloNumVar[1][];IloRange[][] rng =new IloRange[1][];// Evaluate command line option and call appropriate populate method.// The created ranges and variables are returned as element 0 of arrays// var and rng.switch ( args[0].charAt(1) ) {case `r': populateByRow(cplex, var, rng);break;case `c': populateByColumn(cplex, var, rng);break;case `n': populateByNonzero(cplex, var, rng);break;default: usage();return;}// write model to filecplex.exportModel("lpex1.lp");// solve the model and display the solution if one was foundif ( cplex.solve() ) {double[] x =cplex.getValues(var[0]);double[] dj =cplex.getReducedCosts(var[0]);double[] pi =cplex.getDuals(rng[0]);double[] slack =cplex.getSlacks(rng[0]);cplex.output().println("Solution status =" + cplex.getStatus()); cplex.output().println("Solution value =" + cplex.getObjValue());int ncols =cplex.getNcols();for (int j =0; j < ncols; ++j) {cplex.output().println("Column: " + j +" Value =" + x[j] +" Reduced cost =" + dj[j]);}int nrows =cplex.getNrows();for (int i =0; i < nrows; ++i) {cplex.output().println("Row : " + i +" Slack =" + slack[i] +" Pi =" + pi[i]);}}cplex.end();}catch (IloException e) {System.err.println("Concert exception `" + e + "` caught");}}// The following methods all populate the problem with data for the following // linear program://// Maximize// x1 + 2 x2 + 3 x3// Subject To// - x1 + x2 + x3 <=20// x1 - 3 x2 + x3 <=30// Bounds// 0 <=x1 <=40// End//// using the IloMPModeler APIstatic void populateByRow(IloMPModeler model,IloNumVar[][] var,IloRange[][] rng) throws IloException {double[] lb ={0.0, 0.0, 0.0};double[] ub ={40.0, Double.MAX_VALUE, Double.MAX_VALUE};IloNumVar[] x =model.numVarArray(3, lb, ub);var[0] =x;double[] objvals ={1.0, 2.0, 3.0};model.addMaximize(model.scalProd(x, objvals));rng[0] =new IloRange[2];rng[0][0] =model.addLe(model.sum(model.prod(-1.0, x[0]),model.prod( 1.0, x[1]),model.prod( 1.0, x[2])), 20.0);rng[0][1] =model.addLe(model.sum(model.prod( 1.0, x[0]),model.prod(-3.0, x[1]),model.prod( 1.0, x[2])), 30.0);}static void populateByColumn(IloMPModeler model,IloNumVar[][] var,IloRange[][] rng) throws IloException {IloObjective obj =model.addMaximize();rng[0] =new IloRange[2];rng[0][0] =model.addRange(-Double.MAX_VALUE, 20.0);rng[0][1] =model.addRange(-Double.MAX_VALUE, 30.0);IloRange r0 =rng[0][0];IloRange r1 =rng[0][1];var[0] =new IloNumVar[3];var[0][0] =model.numVar(model.column(obj, 1.0).and(model.column(r0, -1.0).and(model.column(r1, 1.0))),0.0, 40.0);var[0][1] =model.numVar(model.column(obj, 2.0).and(model.column(r0, 1.0).and(model.column(r1, -3.0))),0.0, Double.MAX_VALUE);var[0][2] =model.numVar(model.column(obj, 3.0).and(model.column(r0, 1.0).and(model.column(r1, 1.0))),0.0, Double.MAX_VALUE);}static void populateByNonzero(IloMPModeler model,IloNumVar[][] var,IloRange[][] rng) throws IloException { double[] lb ={0.0, 0.0, 0.0};double[] ub ={40.0, Double.MAX_VALUE, Double.MAX_VALUE}; IloNumVar[] x =model.numVarArray(3, lb, ub);var[0] =x;double[] objvals ={1.0, 2.0, 3.0};model.add(model.maximize(model.scalProd(x, objvals)));rng[0] =new IloRange[2];rng[0][0] =model.addRange(-Double.MAX_VALUE, 20.0);rng[0][1] =model.addRange(-Double.MAX_VALUE, 30.0);rng[0][0].setExpr(model.sum(model.prod(-1.0, x[0]),model.prod( 1.0, x[1]),model.prod( 1.0, x[2])));rng[0][1].setExpr(model.sum(model.prod( 1.0, x[0]),model.prod(-3.0, x[1]),model.prod( 1.0, x[2])));}}。
CPLEX简要文档(法语)

Exemple 2
Résoudre le problème
IloCplex mycplex(model); mycplex.exportModel("TPM.lp"); mycplex.setOut(env.getNullStream()); mycplex.setWarning(env.getNullStream()); mycplex.solve();
Un problème d’ordonnancement de machine parallèle
Exemple 2
//Déclarer l’environement et le modèle IloEnv env; IloModel model(env);
//déclarer variables NumVar3Matrix x(env,M); for(k=0;k<M;k++) x[k]=NumVarMatrix(env,N+2); for(k=0;k<M;k++) for(i=0;i<=N+1;i++) x[k][i]=IloNumVarArray(env,N+2,0,1,ILOBOOL); IloNumVarArray Cj(env,DIMEN+1,0,IloInfinity,ILOINT); IloNumVarArray Tj(env,DIMEN+1,0,IloInfinity,ILOINT); IloNumVarArray Obj(env,2,0,IloInfinity,ILOINT);
Exemple 2
Contraints
for (j=1;j<=N;j++) {
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
T集 t节
600 N40=60 N41=250 N42=180
550 2.5
500 3.0 2.0
N30=130 N31=100 N20=300
5个支点方向的直达车流图
第五章 IBM ILOG CPLEX在车流组织优化中的应用 (二) 货物列车编组计划的整数规划模型 变量定义: ������ (1)������������������ ——表示车流(i, j)(含������������ 后方站发往������������ 站改 ������ 编中转的车流)在������������ 站改编的车流量,这里i>j>k,������������������ 为非负整数; (2)������������������ ——0-1变量,表示是否开行列流,若开行,则 ������������������ = 1,反之������������������ = 0,这里i>j。 (3)������ ——所有直达列流在始发站产生的集结车小时 集 总消耗; (4)������ ——所有直达车流在图中支点站的改编车小时 改 总消耗;
第五章 IBM ILOG CPLEX在车流组织优化中的应用 求解结果:
即:min������ = 2360车 · h,根据运行结果可得出最优货物列车 耗 编组计划图:
A4
A3
A2
A1
A0
TБайду номын сангаас t节
600
550 2.5 60+250
500 3.0 2.0
130+300 N43+180 N32+180+130+130 N21+100 N10+60
第五章 IBM ILOG CPLEX在车流组织优化中的应用 (一)货物列车编组计划的数学描述 方向上各技术站所产生的车流应以不同的组合方式编入适当 的列车而将其送往各自的目的地,这些车流的每一种组合方 式为一个编组计划方案。满足划为单独编组到达站基本条件 的车流在一定条件下与其他车流合并编组可能会得到更多的 车小时节省。列车编组计划方案一方面要保证有尽可能大的 经济效果,使方案车小时消耗总额最小或节省最大;另一方 面,方案的选择还必须考虑实际执行的可能性。
第五章 IBM ILOG CPLEX在车流组织优化中的应用 约束条件: 第3组 考虑远程车流压缩到站与较短车流合并的情况
1 ������40 ������41 − ������40 ≥ 0(8) 2 2 (������40 + ������41 )������42 − ������40 − ������41 ≥ 0(9) 1 (������40 + ������30 )������31 − ������30 ≥ 0(10)
第五章 IBM ILOG CPLEX在车流组织优化中的应用
例1:如图这是一个具有5个支点站方向的单组列车编组计划, 表示5个支点方向的直达车流, ������ 表示从某站开行直达列车的集结车小时, 集 ������ 表示车流在某站改编时所消耗的车小时。问在不考虑各个站改编能力 节 的情况下,如何编制一个单组列车编组计划,使得总消耗的车小时最小?
第五章 IBM ILOG CPLEX在车流组织优化中的应用 约束条件: 第1组 考虑������������ 站发出的车流有:
3 2 1 ������40 + ������40 + ������40 + ������40 ������40 = ������40 3 2 ������41 + ������41 + ������41 ������41 = ������41 3 ������42 + ������42 ������42 = ������42
第五章 IBM ILOG CPLEX在车流组织优化中的应用 (三)运用CPLEX求解
dvar int+ X402 in 0..60; dvar int+ X401 in 0..60; dvar int+ X403 in 0..60; dvar int+ X413 in 0..250; dvar int+ X412 in 0..250; dvar int+ X423 in 0..180; dvar int+ X302 in 0..720; dvar int+ X301 in 0..720; dvar int+ X312 in 0..720; dvar int+ X201 in 0..300; //定义决策变量中的整数变量 dvar boolean x40; dvar boolean x41; dvar boolean x42; dvar boolean x30; dvar boolean x31; dvar boolean x20; //定义决策变量中的0-1变量(布尔型变量)
(2) (3) (4)
第五章 IBM ILOG CPLEX在车流组织优化中的应用 约束条件: 第2组 考虑中间各支点站发出的车流
3 2 1 ������30 − ������30 + (������40 + ������30 )������30 − ������40 ≥ ������30 (5) 2 3 ������31 + (������41 + ������31 )������31 − ������41 ≥ ������31 (6) 1 2 2 ������20 + (������40 + ������30 + ������20 )������20 − ������40 − ������30 ≥ ������20 (7)
第五章 IBM ILOG CPLEX在车流组织优化中的应用
(四)求解结果:
/ solution (optimal) with objective 2360 x40 = 0; x41 = 1; x42 = 0; x30 = 0; x31 = 0; x20 = 1; X403 = 0; X413 = 0; X423 = 180; X402 = 0; X412 = 0; X302 = 130; X312 = 100; X401 = 60; X301 = 0; X201 = 0;
第五章 IBM ILOG CPLEX在车流组织优化中的应用
目标函数表达式为: min������ = ������ + ������ 改 耗 集 = ������40 + ������41 + ������42 ������ 4 + ������30 + ������31 ������ 3 集 集 3 3 3 + ������20 ������ 2 + ������40 + ������41 + ������42 ������ 3 节 集 2 2 2 2 + ������40 + ������41 + ������30 + ������31 ������ 2 节 1 1 1 + ������40 + ������30 + ������20 ������ 1 节
模 型 文 件 编 码
第五章 IBM ILOG CPLEX在车流组织优化中的应用 模型文件编码(续):
minimize 600*(x40+x41+x42)+550*(x30+x31)+500*x20+2.5*(X403+X413+X 423)+3*(X402+X412+X302+X312) +2*(X401+X301+X201); //目标 函数 subject to { X403+X402+X401+60*x40 ==60;//① X413+X412+250*x41==250; //② X423+180*x42==180;//③ X302-X301+190*x30 -X403>=130;//④ X312+350*x31 -X413>=100;//⑤ X201+490*x20 -X402-X302>=300;//⑥ 60*x41 -X401<=0;//⑦ 310*x42 -X402-X412>=0;//⑧ 190*x31 -X301>=0;//⑨ ①~⑨是第二节中约束条件(3)~(11)