LINGO Sets&Basic parts

    xiaoxiao2021-03-25  53

    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:

    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;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.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.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.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 :-)

    转载请注明原文地址: https://ju.6miu.com/read-36454.html

    最新回复(0)