AMPLCPLEXTutorial

上传人:沈*** 文档编号:171436218 上传时间:2022-11-26 格式:PPT 页数:22 大小:116.50KB
返回 下载 相关 举报
AMPLCPLEXTutorial_第1页
第1页 / 共22页
AMPLCPLEXTutorial_第2页
第2页 / 共22页
AMPLCPLEXTutorial_第3页
第3页 / 共22页
点击查看更多>>
资源描述
AMPL/CPLEX TutorialESI 6316Applications of OR in Manufacturing2AMPL&CPLEX Introduction AMPLAn Algebraic Modeling Language for Mathematical ProgrammingModeling Language expresses the modelers form in a way that a computer system can understand CPLEXSolver(Optimizer)Algorithms:Simplex Barrier Mixed Integer(Branch&Bound)3AMPL&CPLEX IntroductionAMPLCPLEXMPS FormatConvert to MPSRead MPS fileCall CPLEX ModelUser ApplicationC+,JAVA,VB,EtcCallable Libraries,API4AMPL-2 variable LP 2 variable LP(Two Crude Petroleum)Model file Any text editor e.g.NotepadSave as“twoCrude.mod”Extension.mod specifies a model filevity)(nonnegati 02,1 avail.)n(Venezuela 62 ty)availabili(Saudi 91 reqt.)(lubricant 5.023.012.0 reqt.)fuel(jet 5.122.014.0 reqt.)(gasoline 0.224.013.0 s.t.cost)(total 1520min 21xxxxxxxxxxxx5AMPL Model File(2 var.LP)var x1=0;var x2=0;minimize total_cost:20*x1+15*x2;subject to gasoline_reqt:0.3*x1+0.4*x2=2.0;subject to jetfuel_reqt:0.4*x1+0.2*x2=1.5;subject to lubricant_reqt:0.2*x1+0.3*x2=0.5;subject to saudi_avail:x1=9;subject to venezuelan_avail:x1=0;#amounts available at originsparam demand DEST=0;#amounts required at destinations check:sum i in ORIG supplyi=sum j in DEST demandj;param cost ORIG,DEST=0;#shipment costs per unitvar Trans ORIG,DEST=0;#units to be shippedminimize Total_Cost:sum i in ORIG,j in DEST costi,j*Transi,j;subject to Supply i in ORIG:sum j in DEST Transi,j=supplyi;subject to Demand j in DEST:sum i in ORIG Transi,j=demandj;12Data File:transp.datdata;param:ORIG:supply:=#defines set ORIG and param supply GARY 1400 CLEV 2600 PITT 2900;param:DEST:demand:=#defines DEST and demand FRA 900 DET 1200 LAN 600 WIN 400 STL 1700 FRE 1100 LAF 1000;param cost:FRA DET LAN WIN STL FRE LAF:=GARY 39 14 11 14 16 82 8 CLEV 27 9 12 9 26 95 17 PITT 24 14 17 13 28 99 20;13Data FileYou can also define the sets and param seperatelye.g.data;set ORIG:=GARY CLEV PITT;#defines set ORIGset DEST:=FRA DET LAN WIN STL FRE LAF;#defines set DEST param supply:=#defines param supply GARY 1400 CLEV 2600 PITT 2900;param demand:=#defines param demand FRA 900 DET 1200 LAN 600 WIN 400 STL 1700 FRE 1100 LAF 1000;14.mps file MPS file formatDeveloped by IBMs Mathematical Programming SystemFormat for linear and integer programming problemsCannot be used for nonlinear problems AMPL Syntax to write.mps filewrite mtransp;15Understanding.mps SectionsNAME(title of the problem)ROWS Constraint type E(=),L(=),N(Objective)Row nameCOLUMNS Column name Row name Coefficient(constraint and objective)RHS RHS value16CPLEX Reading a filereadtranspoptimizedisplay solution variables-17Interpretation of ColumnsORIGDESTGARYFRACLEVDETPITTLANWINSTLFRELAFI in ORIGj in DESTColumn#ValueGARYFRA10GARYDET20GARYLAN30GARYWIN40GARYSTL50GARYFRE61100GARYLAF7300CLEVFRA80CLEVDET91200CLEVLAN10600CLEVWIN11400CLEVSTL120CLEVFRE130CLEVLAF14400PITTFRA15900PITTDET160PITTLAN170PITTWIN180PITTSTL191700PITTFRE200PITTLAF213006900Variable Trans was indexed over the set ORIG and DESTDefined the two sets in the following manner18CPLEX Some other commandschange Used to change variable or constraint name Constraint sense Problem type RHS value Etcdisplay Used to view problem characteristics Sensitivity analysis Parameter settings Etc19Class Assignment Pi-Hybrids ModelConstruct a AMPL ModelMake the corresponding data fileSolve using AMPLCreate a.mps fileUse CPLEX to read and optimize the above problemVerify both the results20Script File Script FileAutomatically load model file and data fileCreate random dataDisplay formatted outputRead from and write to text files.Etc.scs extension Executing a script filecommands myscriptfile.scs;21Example of script file for transportation problemmodel transp.mod;data transp1.dat;solve;for i in ORIG,j in DEST if(Transi,j0)then printf%s%s%.0fn,i,j,Transi,j;22Example of Script file for Pi-Hybrids problemmodel c:ampl101pihybrids.mod;data c:ampl101pihybrids.dat;solve;printf nPRINTING FORMATTED OUTPUT.n;printf TOTAL COST=$%.2fn,total_cost;printf Bags to be produced:n;printf Facility#Hybrid#No.of Bagsn;for f in facilities,h in hybrids if(Xf,h0)then printf%d%d%dn,f,h,Xf,h;for f in facilities printf-nBags to be shipped from Facility#%d to:n,f;for r in regionsprintf Region#%dn,r;forh in hybrids printf Hybrid#%d%d Bagsn,h,Yf,h,r;
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档 > 工作计划


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!