Lingo (4)-example

Source: Internet
Author: User
6. optimal selection a drilling team should determine 5 drilling wells from 10 available slots to minimize the total drilling cost. If the 10 bits are codenamed s1, s2 ,..., s10, corresponding drilling costs c1, c2 ,..., c10 is 5, 8, 10, 6, 9, 5, 7, 6, 10, 8. the following conditions must be met for the position selection: (1) s1 and s7, or s9 drilling; (2) s3 or s9 drilling.

This film will be followed by the previous example to write, such as reference can see the next article of the http://blog.csdn.net/yzu_120702117/article/details/38453791

For syntactic problems, refer to the basic article I have summarized earlier.

6. optimal selection

A drilling team needs to determine 5 drilling wells from 10 available slots to minimize the total drilling cost. If the 10 bits are codenamed s1, s2 ,..., s10, corresponding drilling costs c1, c2 ,..., c10 is 5, 8, 10, 6, 9, 5, 7, 6, 10, 8. in addition, the following restrictions must be met for the position selection:
(1) either s1 or s7, or s9 drilling;
(2) If you select s3 or s4, you cannot select s5, or vice versa;
(3) you can select only two of s5, s6, s7, and S8.

Create an integer programming model for this problem and determine the position.

Take the 0-1 variable s_ I. if s_ I = 1, the I-th well is selected. if s_ I = 0, the I-th well is not selected. The mathematical model is as follows:

 

The solution code is as follows:

Model: sets: variables/1 .. 10/: s, cost; endsetsdata: cost = 5 8 10 6 9 5 7 6 10 8; enddatamin = @ sum (variables: cost * s); (s (1) + s (7)-2) * (s (9)-1) = 0 ;! Constraint condition s (3) * s (5) + s (4) * s (5) = 0; @ sum (variables (I) | I # ge #5 # and # I # le #8: s (I) <= 2; @ sum (variable: s) = 5; @ for (variables: @ bin (s); end

 

7. transportation and site selection issues

A company has six construction sites with coordinates (ai, bi) (Unit: km) and cement daily usage di (unit: tons)

(1) There are two existing material farms, located in A (5, 1), B (2, 7), records (xj, yj), and, 2. the daily storage capacity of J is 20 tons each. Suppose there is A straight line between the construction site and the material yard, and A daily supply plan should be formulated, that is, the cement transportation from both A and B to the construction site is the smallest of tons of kilometers, among them, Cij indicates the amount of cement delivered by I site from j yard. You can create a model.

This model can be answered in this way

Model: sets: demand/1 .. 6/: a, B, d; supply/1 .. 2/: x, y, e; link (demand, supply): c; endsetsdata: 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; enddatamin = @ sum (link (I, j): c (I, j) * @ sqrt (a (I)-x (j) ^ 2 + (B (I)-y (j) ^ 2 ));! Target function @ for (demand (I): @ sum (supply (j): c (I, j) = d (I); @ for (supply (j ): @ sum (demand (I): c (I, j) <= e (j); end

 

(2) to reconstruct two new materials, you must determine the position (xj, yj) of the new materials and run cij to minimize the total number of kilometers without changing other conditions. Like the above model, the location variable changes to the location of the field (xj, yj) and becomes a non-linear optimization problem.

Model: sets: demand/1 .. 6/: a, B, d; supply/1 .. 2/: x, y, e; link (demand, supply): c; endsetsdata: 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; enddatainit :! Here the initial values x and y are assigned 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 ));! Target function; @ for (demand (I): @ sum (supply (j): c (I, j) = d (I); @ for (supply (j): @ sum (demand (I): c (I, j) <= e (j); @ for (supply: @ free (x ); @ free (y); end



7. site selection problems

There are 12 major residential areas on an island. The following table lists the locations of each residential area (expressed by plane coordinates x and y, in km) and the number of residents (r. Now we are going to build a service center on the island to provide various services for residents. Where should the service center be built?

Assume that (a, B) is the most reasonable. Model creation

Solve this model:

MODEL:SETS:VAR/1..12/:X,Y,R;ENDSETSDATA:X=0 8.20 0.50 5.70 0.77 2.87 4.43 2.58 0.72 9.76 3.19 5.55;Y=0 0.50 4.90 5.00 6.49 8.76 3.26 9.32 9.96 3.16 7.20 7.88;R=600 1000 800 1400 1200 700 600 800 1000 1200 1000 1100;ENDDATAMIN=@SUM(VAR:@SQRT((X-A)^2+(Y-B)^2)*R);END

 


8. nonlinear integer planning:


The solution is provided here.

Model: sets: row/1 .. 4/: B; col/1 .. 5/: c1, c2, x; link (row, col): a; endsetsdata: c1 =, 2; c2 =-8,-2,-3, -1,-2; a = 1 1 1 11 2 2 1 62 1 6 0 00 0 1 1 5; B = 400,800,200,200; enddata max = @ sum (col: c1 * x ^ 2 + c2 * x); @ for (row (I): @ sum (col (j): a (I, j) * x (j ))
 
  


 

9. marriage issues

The following table lists the probability of pairing any young man or a young man with 10 young people of the same age. A pairing scheme is provided to maximize the total pairing probability.

   W1      W2       W3      W4      W5      W6      W7      W8      W9      W10
M1 1 0.5828  0.2091  0.4154  0.2140  0.6833  0.4514  0.6085  0.0841  0.1210 0.2319
M2 0.4235  0.3798  0.3050  0.6435  0.2126  0.0439  0.0158  0.4544  0.4508 0.2393
M30.5155  0.7833  0.8744  0.3200  0.8392  0.0272  0.0164  0.4418  0.7159 0.0498
M40.3340  0.6808  0.0150  0.9601  0.6288  0.3127  0.1901  0.3533  0.8928 0.0784
M50.4329  0.4611  0.7680  0.7266  0.1338  0.0129  0.5869  0.1536  0.2731 0.6408
M60.2259  0.5678  0.9708  0.4120  0.2071  0.3840  0.0576  0.6756  0.2548 0.1909
M70.5798  0.7942  0.9901  0.7446  0.6072  0.6831  0.3676  0.6992  0.8656 0.8439
M80.7604  0.0592  0.7889  0.2679  0.6299  0.0928  0.6315  0.7275  0.2324 0.1739
M90.5298  0.6029  0.4387  0.4399  0.3705  0.0353  0.7176  0.4784  0.8049 0.1708

M10 0.6405  0.0503  0.4983  0.9334  0.5751  0.6124  0.6927  0.5548  0.9084 0.9943

Take xx_ij as the 0-1 decision variable.

Model:

 

The solution is provided here.

model:sets:man/m1..m10/;woman/w1..w10/;link(man,woman):p,x;endsetsdata:p=0.5828    0.2091    0.4154    0.2140    0.6833    0.4514    0.6085    0.0841    0.1210    0.2319  0.4235    0.3798    0.3050    0.6435    0.2126    0.0439    0.0158    0.4544    0.4508    0.2393  0.5155    0.7833    0.8744    0.3200    0.8392    0.0272    0.0164    0.4418    0.7159    0.0498  0.3340    0.6808    0.0150    0.9601    0.6288    0.3127    0.1901    0.3533    0.8928    0.0784  0.4329    0.4611    0.7680    0.7266    0.1338    0.0129    0.5869    0.1536    0.2731    0.6408  0.2259    0.5678    0.9708    0.4120    0.2071    0.3840    0.0576    0.6756    0.2548    0.1909  0.5798    0.7942    0.9901    0.7446    0.6072    0.6831    0.3676    0.6992    0.8656    0.8439  0.7604    0.0592    0.7889    0.2679    0.6299    0.0928    0.6315    0.7275    0.2324    0.1739  0.5298    0.6029    0.4387    0.4399    0.3705    0.0353    0.7176    0.4784    0.8049    0.1708  0.6405    0.0503    0.4983    0.9334    0.5751    0.6124    0.6927    0.5548    0.9084   0.9943;enddatamax=@prod(man(i):@sum(woman(j):p(i,j)*x(i,j)));@for(woman(j):@sum(link(i,j):x(i,j))=1);@for(man(i):@sum(link(i,j):x(i,j))=1);@for(link:@bin(x));end



10. quantity filling problem

Respectively set 1, 2 ,..., Fill in 16 circles in the figure, so that the number of all circles on each triangle is 81 (4 triangles in total ).
Decision variable: e_ij = 1, enter a_j in the I circle; e_ij = 0, do not enter a_j in the I circle. A_j = j, j = 1, 2, 3,..., 16.

Model:

 


 

The solution is provided here.

model:sets:number/1..16/:a;link(number,number):e;tri1(number)/1 2 3 4 5 6 7 8 9/;tri2(number)/1 2 3 4 16 15 12 11 10/;tri3(number)/4 5 6 7 14 13 12 15 16/;tri4(number)/7 8 9 1 10 11 12 13 14/;endsetsdata:a=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;enddata[obj]max=@sum(link(i,j):e(i,j)*a(j));@for(number(i):@sum(link(i,j):e(i,j))=1);@for(number(j):@sum(link(i,j):e(i,j))=1);@for(link(i,j):@bin(e(i,j)));@sum(number(j):@sum(tri1(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri2(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri3(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri4(i):e(i,j)*a(j)))=81;@sum(link(i,j):e(i,j)*a(j))=136;end

The program in red can be removed, or it can be: min = @ sum (link (I, j): e (I, j) * a (j )), but the results are different, and all results meet the requirements.

1 ~ There are at least three results for filling the number of circles in 16:

(1) 12 11 1 10 7 8 14 13 5 9 4 16 2 6 15 3

(2) 14 3 5 15 8 7 13 4 12 6 11 10 9 2 16 1

(3) 14 11 4 15 9 8 13 2 5 16 3 10 12 6 1 7

In order to obtain more solutions, you can constrain numbers 1 ~ The result of filling in the circle of 16 is not the above three results.

model:sets:number/1..16/:a;link(number,number):e;tri1(number)/1 2 3 4 5 6 7 8 9/;tri2(number)/1 2 3 4 16 15 12 11 10/;tri3(number)/4 5 6 7 14 13 12 15 16/;tri4(number)/7 8 9 1 10 11 12 13 14/;yueshu1:c1;yueshu2:c2;yueshu3:c3;endsetsdata:a=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16;c1=12 11 1 10 7 8 14 13 5 9 4 16 2 6 15 3;c2=14 3 5 15 8 7 13 4 12 6 11 10 9 2 16 1;c3=14 11 4 15 9 8 13 2 5 16 3 10 12 6 1 7;enddata[obj]min=@sum(number(i):@sum(number(j):e(i,j)*a(j)));@for(number(i):@sum(number(j):e(i,j))=1);@for(number(j):@sum(link(i,j):e(i,j))=1);@for(link(i,j):@bin(e(i,j)));@sum(number(j):@sum(tri1(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri2(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri3(i):e(i,j)*a(j)))=81;@sum(number(j):@sum(tri4(i):e(i,j)*a(j)))=81;@sum(link(i,j):e(i,j)*a(j))=136;@sum(yueshu1(j):@sum(link(i,j):e(i,j)))<16;@sum(yueshu2(j):@sum(link(i,j):e(i,j)))<16;@sum(yueshu3(j):@sum(link(i,j):e(i,j)))<16;end

 


Here are five models that can correspond to what I have previously summarized, portals: http://blog.csdn.net/yzu_120702117/article/details/38453791


 


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.