数学建模社区-数学中国

标题: Lingo超经典案例大全 二(每日一资料) [打印本页]

作者: 百年孤独    时间: 2016-7-5 16:23
标题: Lingo超经典案例大全 二(每日一资料)
二、最优选择问题
某钻井队要从10个可供选择的井位中确定5个钻井探油,使总的钻探费用为最小。若10个井位的代号为s1,s2,...,s10,相应的钻探费用c1,c2,...,c10为5,8,10,6,9,5,7,6,10,8.并且井位选择上要满足下列限制条件:
(1) 或选择s1和s7,或选择钻探s9;
(2) 选择了s3或s4就不能选s5,或反过来也一样;
(3) 在s5,s6,s7,s8中最多只能选两个.
试建立这个问题的整数规划模型,确定选择的井位。
取0-1变量s_i,若s_i=1,则表示选取第i个井,若s_i=0,则表示不选取第i个井。建立数学模型如下:

QQ图片20160705161816.png
model:
sets:
variables/1..10/:s,cost;
endsets
data:
cost=5 8 10 6 9 5 7 6 10 8;
enddata
min=@sum(variables:cost*s);
(s(1)+s(7)-2)*(s(9)-1)=0;
s(3)*s(5)+s(4)*s(5)=0;
@sum(variables(i)|i#ge#5#and#i#le#8:s(i))<=2;
@sum(variables:s)=5;
@for(variablesbin(s));
end
求得:
                          Total solver iterations:   26

                       Variable           Value        Reduced Cost
                          S( 1)        1.000000           -4.000000
                          S( 2)        1.000000            0.000000
                          S( 3)        0.000000            2.000000
                          S( 4)        1.000000           -2.000000
                          S( 5)        0.000000            0.000000
                          S( 6)        1.000000           -1.000000
                          S( 7)        1.000000            0.000000
                          S( 8)        0.000000            0.000000
                          S( 9)        0.000000            2.000000
                         S( 10)        0.000000            0.000000

                         Objective value:   31.00000
即选择井S1,S2,S4,S6,S7以达到最小费用31.

三、路径和最短问题:
设平面上有N个点,求一点,使得这个点到所有点距离之和最小。这里,取N=8。数据点是1~5的随机数。
Lingo
model:
sets:
position/1..8/:x,y;
ab/1/:a,b;
endsets
data:
@text('E:\matlab7.0\work\data.txt')=x,y;!读入到matlab的工作空间中;
@text('E:\matlab7.0\work\data1.txt')=a,b;
enddata
x(1)=1+4*@rand(0.12345);
y(1)=1+4*@rand(0.25);
@for(position(i)|i#ge#2:x(i)=1+4*@rand(x(i-1)));!随机产生1~5中的8个点;
@for(position(i)|i#ge#2:y(i)=1+4*@rand(y(i-1)));
[obj]min=@sum(position(i)sqrt((x(i)-a(1))^2+(y(i)-b(1))^2));!目标函数;
@bnd(1,a(1),5);
@bnd(1,b(1),5);
end
matlab:
clear;
clc;
close all;
load('data.txt');
load('data1.txt');
hold on;
plot(data1(1),data1(2),'o','MarkerSize',15,'MarkerFaceColor','r');
plot(data(:,1),data(:,2),'or','MarkerSize',15,'MarkerFaceColor','b');
set(gcf,'Color','w');
set(gca,'FontSize',16)
grid off;
data1=repmat(data1,8,1);
P=[data1(:,1)';data(:,1)'];
Q=[data1(:,2)';data(:,2)'];
plot(P,Q,'g','LineWidth',2);
xlabel('x');
ylabel('y');
title('Solving the problem of the minimun distance of tne sum of all the blue points towards the being known red point.');
gtext(['The minimun distance is ',num2str(10.2685),'.'],'FontSize',16,'Color','r');

QQ图片20160705162548.png

三、运输+选址问题:
某公司有6个建筑工地,位置坐标为(ai, bi) (单位:公里),水泥日用量di (单位:吨)
i        1         2          3          4          5           6
a       1.25      8.75       0.5        5.75        3           7.25
b       1.25      0.75       4.75       5           6.5         7.75
d       3          5          4         7           6            11
(1)现有2料场,位于A (5, 1), B (2, 7),记(xj,yj),j=1,2, 日储量ej各有20吨。
假设料场和工地之间有直线道路,制定每天的供应计划,即从A, B两料场分别向各工地运送多少吨水泥,使总的吨公里数最小。
取决策变量c_ij表示i工地从j料场运来的水泥量。模型(线性模型)为:

QQ图片20160705162701.png
model:
sets:
demand/1..6/:a,b,d;
supply/1..2/:x,y,e;
link(demand,supply):c;
endsets
data:
a=1.25 8.75 0.5 5.75 3 7.25;
b=1.25 0.75 4.75 5 6.5 7.75;
d=3 5 4 7 6 11;
x=5 2;
y=1 7;
e=20 20;
enddata
[obj]min=@sum(link(i,j):c(i,j)*@sqrt((a(i)-x(j))^2+(b(i)-y(j))^2));!目标函数;
@for(demand(i)sum(supply(j):c(i,j))=d(i));
@for(supply(j)sum(demand(i):c(i,j))<=e(j));
end
求得:
C( 1, 1)        3.000000            
C( 1, 2)        0.000000            
C( 2, 1)        5.000000           
C( 2, 2)        0.000000           
C( 3, 1)        0.000000         
C( 3, 2)        4.000000                                 
C( 4, 1)        7.000000                           
C( 4, 2)        0.000000                                
C( 5, 1)        0.000000                                 
C( 5, 2)        6.000000                                 
C( 6, 1)        1.000000                             
C( 6, 2)        10.00000           
Objective value:    136.2275
(2) 改建两个新料场,需要确定新料场位置(xj,yj)和运量cij ,在其它条件不变下使总吨公里数最小。
模型一样,未知量变为料场位置(xj,yj)和运量cij ,变为非线性优化问题。
model:
sets:
demand/1..6/:a,b,d;
supply/1..2/:x,y,e;
link(demand,supply):c;
endsets
data:
a=1.25 8.75 0.5 5.75 3 7.25;
b=1.25 0.75 4.75 5 6.5 7.75;
d=3 5 4 7 6 11;
e=20 20;
enddata
init:
x=5 2;
y=1 7;
endinit
[obj]min=@sum(link(i,j):c(i,j)*@sqrt((a(i)-x(j))^2+(b(i)-y(j))^2));!目标函数;
@for(demand(i)sum(supply(j):c(i,j))=d(i));
@for(supply(j)sum(demand(i):c(i,j))<=e(j));
@for(supplyfree(x);@free(y));
end
求得:
C( 1, 1)        3.000000         
C( 1, 2)        0.000000                                 
C( 2, 1)        0.000000                                 
C( 2, 2)        5.000000                                 
C( 3, 1)        4.000000                                 
C( 3, 2)        0.000000                                 
C( 4, 1)        7.000000                                 
C( 4, 2)        0.000000                                   
C( 5, 1)        6.000000                                 
C( 5, 2)        0.000000                                 
C( 6, 1)        0.000000                                 
C( 6, 2)        11.00000           
(x1,y1)=(3.254884,5.652331)
(x2,y2)=(7.250000,7.750000)
Objective value:   85.26604








欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5