Following is my model written in AMPL language. Could anyone kindly translate it to GAMS language? Thanks in advance!

param m default 26; # must be even
param n default 39;
set X := {0..n};
set Y := {0..m};
set NODES := X cross Y; # A lattice of Nodes
set ANCHORS within NODES
:= { x in X, y in Y :
x == 0 && y >= floor(m/3) && y <= m-floor(m/3) };
param xload {(x,y) in NODES: (x,y) not in ANCHORS} default 0;
param yload {(x,y) in NODES: (x,y) not in ANCHORS} default 0;
param gcd {x in -n..n, y in -n..n} :=
(if x < 0 then gcd[-x,y] else
(if x == 0 then y else
(if y < x then gcd[y,x] else
(gcd[y mod x, x])
)));

set ARCS := { (xi,yi) in NODES, (xj,yj) in NODES:
abs( xj-xi ) <= 3 &&
abs(yj-yi) <=3 &&
abs(gcd[ xj-xi, yj-yi ]) == 1 &&
( xi > xj || (xi == xj && yi > yj) )
};
param length {(xi,yi,xj,yj) in ARCS} := sqrt( (xj-xi)^2 + (yj-yi)^2 );
var comp {ARCS} >= 0;
var tens {ARCS} >= 0;
minimize volume:
sum {(xi,yi,xj,yj) in ARCS}
length[xi,yi,xj,yj] * (comp[xi,yi,xj,yj] + tens[xi,yi,xj,yj]);
subject to Xbalance {(xi,yi) in NODES: (xi,yi) not in ANCHORS}:
sum { (xi,yi,xj,yj) in ARCS }
((xj-xi)/length[xi,yi,xj,yj]) * (comp[xi,yi,xj,yj]-tens[xi,yi,xj,yj])
+
sum { (xk,yk,xi,yi) in ARCS }
((xi-xk)/length[xk,yk,xi,yi]) * (tens[xk,yk,xi,yi]-comp[xk,yk,xi,yi])
=
xload[xi,yi];
;

subject to Ybalance {(xi,yi) in NODES: (xi,yi) not in ANCHORS}:
sum { (xi,yi,xj,yj) in ARCS }
((yj-yi)/length[xi,yi,xj,yj]) * (comp[xi,yi,xj,yj]-tens[xi,yi,xj,yj])
+
sum { (xk,yk,xi,yi) in ARCS }
((yi-yk)/length[xk,yk,xi,yi]) * (tens[xk,yk,xi,yi]-comp[xk,yk,xi,yi])
=
yload[xi,yi];
;
let yload[n,m/2] := -1;
solve;
printf: "%d \n",
card({(xi,yi,xj,yj) in ARCS: comp[xi,yi,xj,yj]+tens[xi,yi,xj,yj] > 1.0e-4})
> structure.out;
printf {(xi,yi,xj,yj) in ARCS: comp[xi,yi,xj,yj] + tens[xi,yi,xj,yj] > 1.0e-4}:
"%3d %3d %3d %3d %10.4f \n",
xi, yi, xj, yj, tens[xi,yi,xj,yj] - comp[xi,yi,xj,yj]
> structure.out;

asked 04 Apr, 19:34

berkaycelik7's gravatar image

berkaycelik7
111
accept rate: 0%

closed 11 Apr, 13:41

fbahr's gravatar image

fbahr ♦
4.6k716

FYI, some starting points can be found @ https://www.or-exchange.org/questions/6021/translate-ampl-code-to-gams ...nevertheless & [most likely] unfortunately (for you), I have to "close" this thread since it -- at least somewhat -- violates the "No homework questions" rule (cf. FAQ).

(11 Apr, 13:39) fbahr ♦

The question has been closed for the following reason "Other" by fbahr 11 Apr, 13:41

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×50
×29

Asked: 04 Apr, 19:34

Seen: 53 times

Last updated: 11 Apr, 13:41

OR-Exchange! Your site for questions, answers, and announcements about operations research.