《AMPLCPLEXTutorial.ppt》由会员分享,可在线阅读,更多相关《AMPLCPLEXTutorial.ppt(22页珍藏版)》请在三一办公上搜索。
1、AMPL/CPLEX Tutorial,ESI 6316Applications of OR in Manufacturing,吞窘旗袋藩臼张位路卷镜狙肾浚英禽颅舀盔遭秧阐志沁宠琅伦逞答兽扩帛AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,2,AMPL&CPLEX Introduction,AMPLAn Algebraic Modeling Language for Mathematical ProgrammingModeling Language expresses the modelers form in a way that a computer syste
2、m can understandCPLEXSolver(Optimizer)Algorithms:SimplexBarrierMixed Integer(Branch&Bound),匿诅裴右竭仔镀瓶煎债却敷崩终焊绘亡路届蹬殷搽钦俱焕洁跌啪奴纬汤酣AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,3,AMPL&CPLEX Introduction,AMPL,CPLEX,MPS Format,Convert to MPS,Read MPS file,Call CPLEX,Model,User ApplicationC+,JAVA,VB,Etc,Callable Libr
3、aries,API,靖细站孜钦烘赌煌止壶在褥井痰兵视赛懒潍吸筋匙孰动谢柑部惰升屿乳逻AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,4,AMPL-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 file,渝床柱恬眉签泞底籽篱坛录羞岁果局救锁庶敷泼珠艇管呀效锯这侯考锅纫AMPL_CPLEX TutorialAMPL_CPLEX Tutori
4、al,5,AMPL 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=6;,闸酮酱浴窖妨光棋璃争到皋摸署酋绍退唁浆架款恬馁抡狠冶班寇
5、些煽纽朗AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,6,Running AMPL(2 var.LP),C:APML101ampl.exe,诱顷茵烤渭啪锹扼奴曲碧骚泊愿命沉篮柱搬糖乖楞掸蔡甄仙滤廊找剔寨须AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,7,Solving bigger problems,Divided into two partsModel file(.mod)Consists of the mathematical modelSetsParametersVariablesObjective functioncons
6、traintsData file(.dat)Actual values forSets and parameters,啪戎界盐詹澈西坛尖定嗡福佰靖辜疫蓬譬梅旦栋危博维佐辑雹哗簇其控恨AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,8,AMPL(Transportation Problem),1400,2600,2900,900,1200,600,400,1700,1100,1000,Gary,Cleveland,Pittsburg,Steel Mills(Origin),Automobile Factories(Destination),Farmington,De
7、troit,Lansing,Windsor,St.Louis,Fremont,Lafayette,Supply in Tons,Demand in Tons,Total Production=Total Requirement,烦越看羽辣滔缠正妒肩粪欲艺巴芝陋挖涅剁充愈凹亡峻孺眯学纫鉴令菲勇AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,9,AMPL(Transportation Problem),腾问例星矩曳首耕发叶泣哼剥确几磐策黔恩芹冤蹈纺益掏杀泡襄僵辽咀唱AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,10,AMPL(Trans
8、portation Problem),财二专谢粮纪孝萝刁硼攘杖因惜茂毫驻缝蛤污事突嚼岳褥纪惫娩络但兼谢AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,11,Model File transp.mod,set ORIG;#originsset DEST;#destinationsparam supply ORIG=0;#amounts available at originsparam demand DEST=0;#amounts required at destinations check:sum i in ORIG supplyi=sum j in DEST d
9、emandj;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;,做秒堰拦傣豆绒骋炙吝殃绘铺教洼鉴扑荒椰您骏井车挫
10、寿恶画链舒姑见耐AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,12,Data File:transp.dat,data;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 L
11、AF:=GARY 39 14 11 14 16 82 8 CLEV 27 9 12 9 26 95 17 PITT 24 14 17 13 28 99 20;,歉摊俱孙窒混怜士驹檄锰扇皑太迎扇鹏骑您聋跃噪衍涎出伴杜撰燃祷爸猪AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,13,Data File,You 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 LA
12、F;#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;,郸讶烃贡骡完胀蛾茵欲榆碍猾盯橙瞪赌登彰遭役营扩型选赦府拘扁第训偿AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,14,.mps file,MPS file formatDeveloped by IBMs
13、Mathematical Programming SystemFormat for linear and integer programming problemsCannot be used for nonlinear problemsAMPL Syntax to write.mps filewrite mtransp;,玉形再唉鸿友铬蜘油氓懂心窥痉汝饰搬驴拽熏网脐潮五对含丛墟笔雏龟挛AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,15,Understanding.mps,SectionsNAME(title of the problem)ROWSConstrai
14、nt type E(=),L(=),N(Objective)Row nameCOLUMNSColumn nameRow nameCoefficient(constraint and objective)RHSRHS value,因河穷星达副起颇徊秉打巩允沟挟致鲸拯痉展迟世俄畦惕组琵她森僧琴躯AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,16,CPLEX,Reading a filereadtranspoptimizedisplay solution variables-,称囊凛搭饶欢扦淮粉播脑克渝辉拄狱搂蒜史谎辽腻怪丁遏羡唐衷唉摄驹义AMPL_CPLEX Tut
15、orialAMPL_CPLEX Tutorial,17,Interpretation of Columns,Variable Trans was indexed over the set ORIG and DEST,Defined the two sets in the following manner,楞墓阑镍呻位赚悍山凸力晚二椰故四眯泰靖种汛履袄壶蜡琴釜铰纵辞滥瞬AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,18,CPLEX,Some other commandschangeUsed to change variable or constraint name
16、Constraint senseProblem typeRHS valueEtcdisplayUsed to view problem characteristicsSensitivity analysisParameter settingsEtc,每涡阶迄秸醛陛妇腔咯垂骇喘速侵吊情棍休守斤划象哪依旦惰确册看扎鹃AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,19,Class Assignment,Pi-Hybrids ModelConstruct a AMPL ModelMake the corresponding data fileSolve using AM
17、PLCreate a.mps fileUse CPLEX to read and optimize the above problemVerify both the results,茨型啦夷奖炼锹蓄网泰舀赌访瘁对凳暮很烹哦坏海湿污踊宋寿剑飞护脖戈AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,20,Script File,Script FileAutomatically load model file and data fileCreate random dataDisplay formatted outputRead from and write to text
18、 files.Etc.scs extensionExecuting a script filecommands myscriptfile.scs;,饼炭潮基牢陷挟抬任序疫析辗莲奈东姿搬渴陪租巢嗅甫痰磷韭悦胳攫筒流AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,21,Example of script file for transportation problem,model transp.mod;data transp1.dat;solve;for i in ORIG,j in DEST if(Transi,j0)then printf%s%s%.0fn,i,j,
19、Transi,j;,既网聚苔屁在瞬主痈杭足妊盘尊饲套元誊绢温垢汽赤况溶循见手卸况身景AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,22,Example of Script file for Pi-Hybrids problem,model 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
20、 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;,结柿担税肢迎亲垂迸炕敝洼戚米测猪化耀彬遭藕晒藐羡双辛习溢闸舷弄垂AMPL_CPLEX TutorialAMPL_CPLEX Tutorial,