LINGO Sets&Basic parts

Problem

Sailing company SAILCO need to decide how many sailboats to produce per quarter in the next four quarters. The next four quarters’ demand for vessels is 40,60,75 and 25. These demand must be met in time. Normal production capacity of each quarter is 40 sailboat, and the production cost for each sailboat is $400. The production cost per vessel is $450 if you work overtime . At the end of each quarter, the inventory fee for each ship is $20. Assuming the production time is 0 and the initial stock is 10 ships. How to schedule production can minimize the total cost?

Solution

It is important for us to understand the concept of Set and Attribute in LINGO13 before we solve this problem.

Let us use DEM, NP, OP and INV to represent the demand, normal production, overtime production and inventory respectively. The DEM is known while NP, OP and INV are unknown.

The objective function is the sum of all costs:

MIN=400NP(I)+450OP(I)+20INV(I)

The constraints are:
1) Constraint of productivity:
NP(I)<40I=1,2,3,4

2) Product quantity balance:
INV(I)=INV(n1)+NP(I)+OP(I)DEM(I),I=1,2,3,4;INV(0)=10

3)Sign restrains (as all variables should be non negative).

Code

MODEL:
SETS:
    QUARTERS/1,2,3,4/:DEM,NP,OP,INV;
ENDSETS
DATA:
    DEM=40,60,75,25;
ENDDATA
MIN=@SUM(QUARTERS(I):400*NP(I)+450*OP(I)+20*INV(I));
@FOR(QUARTERS(I):NP(I)<40);
@FOR(QUARTERS(I)|I#GT#1:
    INV(I)=INV(N-1)+NP(I)+OP(I)-DEM(I););
INV(1)=10+NP(1)+OP(1)-DEM(1);
END

Summary

The basic parts of a LINGO program:

  1. SET-ENDSETS part:
    You can create some sets in this part, and if there are too many elements in one set to list, you can use ... to omit some subscripts, like
    QUARTERS/1...1000/: DEM, NP, OP, INV;
  2. objective function and constraints part:
    This is the only part which has no special mark. In fact, any thing outside other four parts belongs to this part.
  3. DATA-ENDDATA part:
    In this part, you can input the basic information for the sets defined before. And usually we use attribute=value_list(constant) to assign values to elements. If there are some variables which you don’t want to assign until running the program, you can use variable=? to do it.
  4. INIT-ENDINIT part:
    This part is similar with the DATA-ENDDATA part, and you can use attribute=value_list(constant) to assign initial values to elements. But these values just help computer to reduce calculation time and may help you get a better answer, yet they can be changed during the iteration.
  5. CALC-ENDCALC part:
    Some basic calculation can be done in this part. As the raw data may can’t be used in the model, they can be pretreated before they are used in objective function and constraints part.

End of 2

I’m too busy these day, and this tutorial may be refreshed a little slow. Hope you like it :-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值