Very Urgent Error 172 Solutions

Problems with modeling
Post Reply
chuckly
User
User
Posts: 3
Joined: 5 years ago

Very Urgent Error 172 Solutions

Post by chuckly »

Hello

We are modeling the liner shipping routes. And we are using gams for solution. But we can't do the syntax correct. Error is in this section.

set

s "Service Routes" / sr1,sr2,T,F /



r(p,s) "Ship Routes"
/(HK1.JK1.SG1.HK1).sr1 , (HK2.XM2.SG2.CB2.SG2.HK2).sr2 /


a(o,d,i,p,pp,s) "Container Path"
/ CB.JK.1.CB2.SG2.sr2,
CB.JK.1.SG2.SG1.T,
CB.JK.1.SG1.HK1.sr1,
CB.JK.1.HK1.JK1.sr1,
CB.JK.2.CB2.JK1.F,
CB.JK.3.CB2.SG2.sr2,
CB.JK.3.SG2.HK2.sr2,
CB.JK.3.HK2.HK1.T,
CB.JK.3.HK1.JK1.sr1,

It's giving Error 172 for sr1,sr2,T and F to us. Please help me for solving this problem
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Very Urgent Error 172 Solutions

Post by Renger »

Hi
If you have a very urgent error, you should at least provide the complete code that produces the error, otherwise it will be just guessing. So at least provide the code inclusive of the part that produces the error. Have a look at the "Rules" of this forum (app.php/rules) on how to get a fast answer.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
chuckly
User
User
Posts: 3
Joined: 5 years ago

Re: Very Urgent Error 172 Solutions

Post by chuckly »

Hi again,

Thank you for your answer. Sorry for that problem, I'm writing full code now. Thank you for your interest


set
o "Origin port" /HK,JK,SG,XM,CB/
p "Ports" /HK1,HK2,JK1,SG1,SG2,XM2,CB2/
e "Vessel Classes" /A,B,C/
v "Vessel Speed" /17k, 21k, 25k/
i "Number of ways for go to origin to destination point" /1*10/
;

alias(o,d) ;
alias(p,pp) ;

set

s "Service Routes" / sr1,sr2,T,F /

Tr "Transfer Arc" /HK1.HK2 , SG1.SG2/

parameter

r(p,s) "Ship Routes"
/(HK1.JK1.SG1.HK1).sr1 , (HK2.XM2.SG2.CB2.SG2.HK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JK.1.SG1.HK1.sr1,
SG.JK.1.HK1.JK1.sr1,
SG.JK.2.SG1.JK1.F, / ;



table t1(o,d) "hours between ports in service 2"
HK SG XM CB
HK 66
SG 158 148
XM 172
CB 148 128
;

table t2(o,d) "hours between ports in service 1"

HK SG JK
HK 178
SG 128
JK 30
;

parameter
teu(e) "Ship size" /A 4000, B 9000, C 19000/

f(e) "Weekly charter rate for vessel e in $" /A 45000 ,B 70000 ,C 110000/

Ne(e) "Available vessel" /A 10, B 7, C 5/

k(p) "Demand for port p" / HK1 100, JK1 100, SG1 100, HK2 100, XM2 100, SG2 100, CB2 100 /
;


table dis(o,d) "Nautical Miles"
HK JK SG CB XM
HK 1789 287
JK 525 ??????????????
SG 1460 1567
CB 1567
XM 1653
;

table g(v,e) "Fuel Consumption per mile Based on Speed and Vessel Class"
A B C
17k 0.098 0.196 0.269
21k 0.158 0.317 0.396
25k 0.258 0.466 0.600
;

parameter U(s) "vessel capacity in service s" /sr1 20000, sr2 40000/
;


table n(e,s) "The number of vessel of class e(s) required to maintain weekly frequency"
A B C
sr1 1 1 1
sr2 2 1 1

;

scalar
cm "Metric Ton Fuel Cost in $" /650/

;

variables
c(s) "Cost of Service"
c(ro) "Cost of a Path ro"
x(ro) "Amount of Commodity k Sent Along the Path"

z "Objective Function"
;

Binary variable y(s)



equations
objective "Total Cost"
cargo_flow(k) "All Cargo is Either Transported or Forfeited"
capacity(a) "Linked the Cargo Paths with the Service Capacity Installed"
fleet_a(e) "The Selected Services can be Operated by the Available Fleet"
cost(s) "Cost of selected service"

;

objective.. z =e= sum(s,(c(s)*y(s))+(sum(ro, c(ro)*x(ro)))) ;

cost(s).. c(s) =e= sum(e,n(e,s)*f(e)) + sum((e,v),cm*g(e,v))*sum((o,d),dis(o,d)) ;

cargo_flow(k).. sum(ro,x(ro)) =e= sum(p,k(p));

capacity(a).. sum(ro,x(ro))- sum(s,U(s)*y(s)) =l= 0;

fleet_a(e).. sum(s,n(e,s)*y(s)) =l= Ne(e);


model TEZZZ /all/ ;
solve TEZZZ using MIP minimizing z;
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Very Urgent Error 172 Solutions

Post by Renger »

Hi

Your error comes from adding the same set elements twice (line 40 and line 42 are equal.

Code: Select all

  
  40  HK.SG.1.HK1.JK1.sr1,
  41  HK.SG.1.JK1.SG1.sr1,
  42  HK.SG.1.HK1.JK1.sr1,
  ...
  
This is not the first mistake in your code. Always correct the earlier error before you proceed with the following ones, but the latter can be caused by the first error.
Your definition of the mapping r(p,s) mentions one element twice in both mappings. Furthermore, you should use commas to separate the elements of p that are mapped to the same element of s.

Cheers
Renger
PS. If you copy the code into a question, please put code tags around the code. Or by clicking on the </> symbol in the editor icons lists and pasting the code between those two code tags. In this way, your code is easier copied as the formatting of tabs and empty spaces is kept.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
chuckly
User
User
Posts: 3
Joined: 5 years ago

Re: Very Urgent Error 172 Solutions

Post by chuckly »

First thank you for solving this problem. It worked. But we have another problem, in our model;

CB.JK.1.CB2.SG2.sr2,
CB.JK.1.SG2.SG1.T,
CB.JK.1.SG1.HK1.sr1,
CB.JK.1.HK1.JK1.sr1,
CB.JK.2.CB2.JK1.F,
CB.JK.3.CB2.SG2.sr2,
CB.JK.3.SG2.HK2.sr2,
CB.JK.3.HK2.HK1.T,
CB.JK.3.HK1.JK1.sr1,

For example, about this writings, we wrote some of our arcs(9), the first 4 row is first path (we can understand with cb.jk.1 = "1" is the number of path). CB.JK.2 is the second path and others are 3th. But we can not define that in another set(path set). we have constraints that include paths and arcs so we should write another set like cb.jk.1(cb2.sg2.sr2,sg2.sg1.t,sg1.hk1.sr1,hk1.jk1.sr1). T is transfer arc between ships in same port and F is forfeit arc which determines that directly transporting and sr2 and sr1 are ship routes.
Post Reply