数学建模社区-数学中国
标题:
【分段函数】【多周期】【最大值问题】
[打印本页]
作者:
ustb_zxc
时间:
2012-11-28 17:58
标题:
【分段函数】【多周期】【最大值问题】
各位零友,谁知道怎么把下面的代码改成多个周期的y值之和最小吗?
比如说6个周期,自变量x(1)~x(6)始终在【200,1500】之间,求y(1)+y(2)+y(3)+y(4)+y(5)+y(6)最值。
代码如下
Model:
SETS:
Points/1..4/: b, c, y, z; ! 端点数为4,即分段数为3;
ENDSETS
DATA:
b=0 500 1000 1500;
c=0 5000 9000 12000;
y=,,,0; ! 增加的虚拟变量y(4)=0;
ENDDATA
Max= 4.8*x11 + 4.8*x21 + 5.6*x12 + 5.6*x22 - @sum(Points: c*z);
x11+x12 < x + 500;
x21+x22 < 1000;
0.5*x11 - 0.5*x21 > 0;
0.4*x12 - 0.6*x22 > 0;
@sum(Points: b*z)=x;
@for(Points(i)|i#eq#1: z(i) <= y(i));
@for(Points(i)|i#ne#1: z(i) <= y(i-1)+y(i));
@sum(Points: y)=1;
@sum(Points: z)=1;
@for(Points: @bin(y));
end
作者:
olh2008
时间:
2012-11-28 22:31
你说到了周期及自变量和目标函数,但是没有说具体的函数表达式。光看你的代码也不清楚你建的模型,你能不能仔细描述一下你的问题?
作者:
ustb_zxc
时间:
2012-11-28 23:28
olh2008 发表于 2012-11-28 22:31
你说到了周期及自变量和目标函数,但是没有说具体的函数表达式。光看你的代码也不清楚你建的模型,你能不能 ...
【问题补充】分段函数如下所示:
y=10*x 0<x<=500
y=8*x+1000 500<x<=1000
y=-x+9000 1000<x<=1500
在period(1..6)6个周期中,x>=a,a=(300,800,1300,1400,600,900),求@sum(y)的最大值。
作者:
sorjor
时间:
2012-11-29 10:08
你第一个模型好像是个例子,你下面的模型可以通过lingo10以上的版本中的子模型来求解。
程序如下(我不知道我有没有正确的理解你的模型)
model:
sets:
ys/1..6/:a;
endsets
data:
a=300 800 1300 1400 600 900;
enddata
submodel obj1:
x>=a(1);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
submodel obj2:
x>=a(2);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
submodel obj3:
x>=a(3);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
submodel obj4:
x>=a(4);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
submodel obj5:
x>=a(5);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
submodel obj6:
x>=a(6);
y=@if(x#LE#500,10*x,@if(x#LE#1000,8*x+1000,-x+9000));
max=y;
endsubmodel
calc:
@write('a=300时的解',@newline(1));
@solve(obj1);
@write('a=800时的解',@newline(1));
@solve(obj2);
@write('a=1300时的解',@newline(1));
@solve(obj3);
@write('a=1400时的解',@newline(1));
@solve(obj4);
@write('a=600时的解',@newline(1));
@solve(obj5);
@write('a=900时的解',@newline(1));
@solve(obj6);
endcalc
end
作者:
sorjor
时间:
2012-11-29 10:09
运行结果如下:
a=300时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 9000.000
Objective bound: 9000.000
Infeasibilities: 0.000000
Extended solver steps: 3
Total solver iterations: 22
Variable Value Reduced Cost
X 1000.000 0.000000
Y 9000.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 700.0000 0.000000
2 0.000000 1.000000
3 9000.000 1.000000
a=800时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 9000.000
Objective bound: 9000.000
Infeasibilities: 0.000000
Extended solver steps: 2
Total solver iterations: 8
Variable Value Reduced Cost
X 1000.000 0.000000
Y 9000.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 200.0000 0.000000
2 0.000000 1.000000
3 9000.000 1.000000
a=1300时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 7700.000
Objective bound: 7700.000
Infeasibilities: 0.000000
Extended solver steps: 0
Total solver iterations: 0
Variable Value Reduced Cost
X 1300.000 0.000000
Y 7700.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 0.000000 -1.000000
2 0.000000 1.000000
3 7700.000 1.000000
a=1400时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 7600.000
Objective bound: 7600.000
Infeasibilities: 0.000000
Extended solver steps: 0
Total solver iterations: 0
Variable Value Reduced Cost
X 1400.000 0.000000
Y 7600.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 0.000000 -1.000000
2 0.000000 1.000000
3 7600.000 1.000000
a=600时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 9000.000
Objective bound: 9000.000
Infeasibilities: 0.000000
Extended solver steps: 2
Total solver iterations: 8
Variable Value Reduced Cost
X 1000.000 0.000000
Y 9000.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 400.0000 0.000000
2 0.000000 1.000000
3 9000.000 1.000000
a=900时的解
Linearization components added:
Constraints: 30
Variables: 16
Integers: 12
Global optimal solution found.
Objective value: 9000.000
Objective bound: 9000.000
Infeasibilities: 0.000000
Extended solver steps: 2
Total solver iterations: 8
Variable Value Reduced Cost
X 1000.000 0.000000
Y 9000.000 0.000000
A( 1) 300.0000 0.000000
A( 2) 800.0000 0.000000
A( 3) 1300.000 0.000000
A( 4) 1400.000 0.000000
A( 5) 600.0000 0.000000
A( 6) 900.0000 0.000000
Row Slack or Surplus Dual Price
1 100.0000 0.000000
2 0.000000 1.000000
3 9000.000 1.000000
作者:
xiao小鬼
时间:
2012-12-3 15:10
4楼好给力啊,什么问题都解决的了,以后有问题就找你了
作者:
songsong000
时间:
2013-8-30 21:58
强~ 学习了
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5