Can someone please tell me what is wrong with my ampl code?
set Q; #quarters
set c; #cities
param d{i in c, j in c}; # distance between city i and city j
param D{i in c, q in Q}; # demand of each city in each quarter
param U{i in c, q in Q}; # produced units limit for production facility in city i in quarter q (production capacity)
param ccp{i in c}; # contract cost for production facility in city i
param cp{q in Q}; # cost per unit produced in quarter q
param cw{q in Q}; # cost per unit warehoused at the end of quarter q
param t1 = .1; # the transportation cost as a function of the distance to wh
param t2 = .125; # the transportation cost as a function of the distance to city
var fp{i in c} binary; # 1 production centers in city i was selected, 0 o.w. (total of 4 cities)
var fw{i in c} binary; # 1 production centers in city i was selected, 0 o.w. (total of 3 cities)
var xp{x in c,q in Q}>=0; # the numb of units to be produced in each production facility and quarter
var xw{i in c, q in Q}>=0; # the number of units in each warehouse’s inventory at the end of each quarter
#var ypi{i in c, q in Q}; # the number of units transported from each production facility to each city
#var ywi{i in c, q in Q}; # the number of units transported from each warehouse to each city in each quarter
#var ypw {i in c,q in Q}; # the units are transported from each production facility to each warehouse in each quarter
minimize tot_cost:
sum{i in c, q in Q} cp[q]*xp[i,q]*fp[i] + sum{i in c} ccp[i]*fp[i] + sum{q in Q,i in c} cw[q]*xw[i,q]*fw[i] + sum{i in c,j in c,q in Q} t1*d[i,j]*xp[i,q]*fp[i] + sum{i in c, j in c,q in Q} t2 *d[i,j]*xp[i,q]*fp[i];
s.t.
#Production_Cities: sum{i in c} fp[i] = 4;
#WH_Cities: sum{i in c}fw[i] = 3;
relation{i in c, q in Q}: xp[i,q]<= 1000000 * fp[i]
Demand{i in c, q in Q}: xp[i,q]*fp[i] = D[i,q]; # quarterly demand of a city must be met exactly
Capacity{i in c, q in Q}: xp[i,q]*fp[i] <=U[i,q]*fp[i];# units output by production facility must be less than its (production capacity) for each quarter (<=U)
# One production facility must be contracted from the 6 most populated cities, another from the next 6, another from the next 6, and the last from the 7 least populated cities.
# contracts with warehouses can change from quarter to quarter, but the locations must be other than where production facilities are contracted. (fw != lofp)
#At the end of each subsequent quarter (except 1), warehouse’s inventory must equal the ending inventory from the previous quarter, plus units arriving from production during the current quarter, minus units delivered from it to satisfy demands during the current quarter.
# Warehous_Units{i in c, q in Q} : xw[i,q]*fw[i]=xw[i,q]*fw[i]+xp[i,q]*fp[i]-D[i,q];
The following is the correct data file:
# Set containing cities numbered from 1 to n=25
data;
set c:= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25;
#Time Quarters
set Q:= 1 2 3 4;
# Distance Matrix ( Distance between city i and city j)
param d : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25:=
1 0.5 347.64 663.04 529.03 428.1 1062.22 433.68 435.54 519.57 525.4 886.53 1000.53 627.82 442.85 26.1 723.77 2187.62 401.28 59.13 457.49 464.55 584.59 168.72 525.13 433.5
2 347.64 0.5 786.46 846.61 440.99 987.72 439.97 443.34 836.61 842.72 899.22 881.01 626.23 161.5 373.73 838.9 1846.91 748.7 291.04 110.71 678.15 262.39 468.75 842.73 445.16
3 663.04 786.46 0.5 535.62 354.43 578.65 358.12 354.74 530.15 533.25 312.35 616.9 265.75 717.24 660.71 61.02 2470.16 712.36 687.95 863.61 246.71 827.49 523.04 534.45 351.54
4 529.03 846.61 535.62 0.5 625.08 1108.75 633.67 632.33 10.1 3.98 847.85 1122.88 712.56 881.81 507.03 580.19 2690.08 256.73 586.25 955.67 319.25 1028.46 378.45 3.92 627.51
5 428.1 440.99 354.43 625.08 0.5 634.12 8.64 8.32 615.74 621.31 477.53 579.94 205.34 363.07 438.8 402.18 2145.9 674.52 425.75 510.7 336.28 480.46 369.07 621.99 5.44
6 1062.22 987.72 578.65 1108.75 634.12 0.5 628.61 626.71 1102.4 1106.06 275.29 157.22 441.08 841.77 1072.57 547.49 2233.02 1250.91 1057.33 1004.25 797.04 858.88 984.79 1107.2 628.73
7 433.68 439.97 358.12 633.67 8.64 628.61 0.5 3.42 624.34 629.9 475.2 572.98 202.06 359.13 444.73 405.06 2139.26 682.84 430.38 508.13 344.22 474.93 376.77 630.58 7.3
8 435.54 443.34 354.74 632.33 8.32 626.71 3.42 0.5 623.02 628.57 472.3 571.83 199.37 362.5 446.43 401.64 2142.12 682.78 432.6 511.56 342.04 478.1 377.37 629.25 4.88
9 519.57 836.61 530.15 10.1 615.74 1102.4 624.34 623.02 0.5 6.14 842.25 1115.49 704.67 871.72 497.67 575.37 2680 253.03 576.69 945.65 311.61 1018.38 368.52 6.41 618.21
10 525.4 842.72 533.25 3.98 621.31 1106.06 629.9 628.57 6.14 0.5 845.44 1119.8 709.3 877.83 503.44 578.06 2686.14 255.46 582.57 951.76 316.07 1024.48 374.59 1.32 623.76
11 886.53 899.22 312.35 847.85 477.53 275.29 475.2 472.3 842.25 845.44 0.5 355.39 275.07 780.75 891.49 274.6 2376.28 1012.36 894.88 945.19 547.48 844.58 778.83 846.63 472.33
12 1000.53 881.01 616.9 1122.88 579.94 157.22 572.98 571.83 1115.49 1119.8 355.39 0.5 416.19 727.27 1014.14 600.16 2078.97 1235.19 987.48 884.7 804.05 726.22 946.35 1120.84 574.87
13 627.82 626.23 265.75 712.56 205.34 441.08 202.06 199.37 704.67 709.3 275.07 416.19 0.5 517.12 636.09 286.1 2211.99 820.24 629.61 678.76 393.67 600.66 543.78 710.27 199.98
14 442.85 161.5 717.24 881.81 363.07 841.77 359.13 362.5 871.72 877.83 780.75 727.27 517.12 0.5 467.72 762.98 1815.8 828.75 395.54 165.49 659.87 147.94 519.72 878.08 365.77
15 26.1 373.73 660.71 507.03 438.8 1072.57 444.73 446.43 497.67 503.44 891.49 1014.14 636.09 467.72 0.5 721.62 2213.2 375.24 84.49 483.56 455.66 610.02 154.88 503.13 444.16
16 723.77 838.9 61.02 580.19 402.18 547.49 405.06 401.64 575.37 578.06 274.6 600.16 286.1 762.98 721.62 0.5 2497.85 766.82 748.06 912.84 303.58 867.66 583.97 579.3 398.83
17 2187.62 1846.91 2470.16 2690.08 2145.9 2233.02 2139.26 2142.12 2680 2686.14 2376.28 2078.97 2211.99 1815.8 2213.2 2497.85 0.5 2585.79 2128.71 1736.53 2470.63 1675.08 2314.61 2686.25 2146.56
18 401.28 748.7 712.36 256.73 674.52 1250.91 682.84 682.78 253.03 255.46 1012.36 1235.19 820.24 828.75 375.24 766.82 2585.79 0.5 459.17 858.75 466.65 975.22 320.99 254.32 678.62
19 59.13 291.04 687.95 586.25 425.75 1057.33 430.38 432.6 576.69 582.57 894.88 987.48 629.61 395.54 84.49 748.06 2128.71 459.17 0.5 400.21 502.97 534.05 218.5 582.34 431.19
20 457.49 110.71 863.61 955.67 510.7 1004.25 508.13 511.56 945.65 951.76 945.19 884.7 678.76 165.49 483.56 912.84 1736.53 858.75 400.21 0.5 775 194.23 578.45 951.8 514.17
21 464.55 678.15 246.71 319.25 336.28 797.04 344.22 342.04 311.61 316.07 547.48 804.05 393.67 659.87 455.66 303.58 2470.63 466.65 502.97 775 0.5 795.94 304.07 317.07 337.2
22 584.59 262.39 827.49 1028.46 480.46 858.88 474.93 478.1 1018.38 1024.48 844.58 726.22 600.66 147.94 610.02 867.66 1675.08 975.22 534.05 194.23 795.94 0.5 667.63 1024.76 482.08
23 168.72 468.75 523.04 378.45 369.07 984.79 376.77 377.37 368.52 374.59 778.83 946.35 543.78 519.72 154.88 583.97 2314.61 320.99 218.5 578.45 304.07 667.63 0.5 374.54 373.79
24 525.13 842.73 534.45 3.92 621.99 1107.2 630.58 629.25 6.41 1.32 846.63 1120.84 710.27 878.08 503.13 579.3 2686.25 254.32 582.34 951.8 317.07 1024.76 374.54 0.5 624.45
25 433.5 445.16 351.54 627.51 5.44 628.73 7.3 4.88 618.21 623.76 472.33 574.87 199.98 365.77 444.16 398.83 2146.56 678.62 431.19 514.17 337.2 482.08 373.79 624.45 0.5
;
# Demand of each city i in Quarter q
param D: 1 2 3 4:=
1 3452 5753 4602 9204
2 3515 5858 4687 9373
3 3535 5892 4713 9426
4 3536 5893 4714 9429
5 3662 6104 4883 9766
6 3691 6151 4921 9842
7 3805 6342 5074 10147
8 3850 6416 5133 10266
9 3856 6426 5141 10282
10 3997 6662 5330 10659
11 4163 6939 5551 11102
12 4460 7433 5947 11893
13 4768 7947 6357 12715
14 4926 8211 6569 13137
15 5021 8369 6695 13390
16 5323 8872 7097 14194
17 5728 9546 7637 15274
18 6019 10032 8025 16051
19 6553 10922 8737 17475
20 8525 14208 11366 22732
21 10115 16858 13486 26973
22 10548 17580 14064 28128
23 12213 20355 16284 32568
24 24323 40538 32431 64861
25 48839 81399 65119 130238
;
# Produced units limit for production facility in city i in quarter q
param U: 1 2 3 4:=
1 97485 97485 64990 103984
2 97454 97454 64969 103951
3 97444 97444 64962 103940
4 97443 97443 64962 103940
5 97380 97380 64920 103872
6 97366 97366 64911 103857
7 97309 97309 64872 103796
8 97286 97286 64858 103772
9 97283 97283 64856 103769
10 97213 97213 64808 103693
11 97130 97130 64753 103605
12 96981 96981 64654 103447
13 96827 96827 64551 103282
14 96748 96748 64499 103198
15 96701 96701 64467 103147
16 96550 96550 64367 102986
17 96347 96347 64232 102771
18 96202 96202 64134 102615
19 95935 95935 63956 102330
20 94949 94949 63299 101279
21 94154 94154 62769 100431
22 93937 93937 62625 100200
23 93105 93105 62070 99312
24 87050 87050 58033 92853
25 74792 74792 49861 79778
;
#Contract cost for production facility in city i
param: ccp :=
1 5362
2 5667
3 5845
4 5971
5 6072
6 6154
7 6225
8 6287
9 6341
10 6391
11 6437
12 6482
13 6525
14 6566
15 6604
16 6641
17 6677
18 6712
19 6747
20 6790
21 6835
22 6877
23 6922
24 6999
25 7121
;
# Cost per unit produced in quarter q
param cp :=
1 0.75
2 1.0
3 1.0
4 1.5
;
# Cost per unit warehoused at the end of quarter q
param cw :=
1 0.5
2 0.5
3 0.75
4 0.10
;
"Almost" Good Answers: