ILOG的一个基本应用——解决运输问题、转运问题

一、Ilog软件

该软件用来解决优化问题,大部分是线性问题,深一点的其他内容还不清楚。只知道一些基础的应用,网上相关内容很少。接下来就解决一个简单的运输问题

二、运输问题

 

ILOG的一个基本应用——解决运输问题、转运问题

数学模型

ILOG的一个基本应用——解决运输问题、转运问题

ILOG OPL程序

 

{string} CitiesA=...;

{string} CitiesB=...;

float capacity = ...;

float supply[CitiesA] =...;

float demand[CitiesB] =...;

assert    

    sum(o in CitiesA) supply[o] == sum(d in CitiesB) demand[d];

float cost[CitiesA][CitiesB] = ...;

dvar float+ trans[CitiesA][CitiesB];

constraint ct1;

constraint ct2;

constraint ct3;

minimize sum( o in CitiesA , d in CitiesB) cost[o][d] * trans[o,d];



subject to {

ct1=forall(o in CitiesA) 

	sum(d in CitiesB) trans[o][d] == supply[o]; 

ct2=forall(d in CitiesB) 

	sum(o in CitiesA) trans[o][d] == demand[d];

ct3=forall(o in CitiesA , d in CitiesB)

	trans[o,d] <= capacity;

} 

数据文件

 

 

CitiesA = { A1 A2 A3 A4 A5};

CitiesB={ B1  B2  B3  B4  B5  B6  B7 B8 };  

capacity  = 825;

supply =[ 400 700 800 450 550];

demand =[300 400 100 275 650 325 300 550];               

cost =[[ 30  10  8  10 11 71 6 50]

      [ 22   7 10   7 21 82 13 30]

      [ 19  11 12  10 25 83 15 26]

      [ 15  20 30  40 50 25 16 12]

      [ 10  49 23  50 28 43 56 20]

      ]; 

 

三、转运问题

 

ILOG的一个基本应用——解决运输问题、转运问题


ILOG的一个基本应用——解决运输问题、转运问题

Ilog opl实现

{string} CitiesA=...;

{string} CitiesB=...;

{string} CitiesC=...;

float capacity = ...;

float supply[CitiesA] =...;

float demand[CitiesB] =...;

float cost1[CitiesA][CitiesC] = ...;

float cost2[CitiesC][CitiesB]=...;

dvar float+ trans1[CitiesA][CitiesC];

dvar float+ trans2[CitiesC][CitiesB];

constraint ct1;

constraint ct2;

constraint ct3;

constraint ct4;

minimize sum( o in CitiesA , t in CitiesC) cost1[o][t] * trans1[o][t]+

		 sum( t in CitiesC , d in CitiesB) cost2[t][d] * trans2[t][d];



subject to {

ct1=forall(o in CitiesA) 

	sum(t in CitiesC) trans1[o][t] <= supply[o]; 

ct2=forall(d in CitiesB) 

	sum(t in CitiesC) trans2[t][d] == demand[d];

ct3=forall(t in CitiesC)

	sum(o in CitiesA)trans1[o][t] == sum(d in CitiesB)trans2[t][d];

ct4=forall(o in CitiesA,d in CitiesB,t in CitiesC)

{

    trans1[o,t]<=capacity;

    trans2[t,d]<=capacity;

}	

} 


数据

 

 

CitiesA = { A1 A2 A3};

CitiesB={ B1  B2  B3  B4  };  

CitiesC={C1 C2 C3 C4};

capacity  = 20;

supply =[7 4 9];

demand =[3 6 5 6];               

cost1 =[[2 1 4 3 ]

        [3 5 100 2 ]

        [1 100 2 3 ]

       ]; 

cost2=[[2 8 4 6]

       [4 5 2 7]

       [1 8 2 4]

       [1 100 2 6]

      ]; 


对于产地、转运站、销地之间都可以互相运输的复杂情况,建模不够理想,没有实现。

 








 

你可能感兴趣的:(log)