# Questions tagged [gams-math]

GAMS (General Algebraic Modeling System) is a high-level modeling system for mathematical optimization.

315
questions

**0**

votes

**1**answer

13 views

### How to call the same index in each of 2 dimensions in a GAMS variable?

I am running a model in GAMS with a number of variables with 2 dimensions, calling the indexes i and j respectively. I have a few constraints relating to just the "diagonal" entries, so I ...

**0**

votes

**0**answers

38 views

### Stationarity conditions in Pyomo

I am trying to implement MCP (Mixed Complementarity Problem) problem in pyomo with PATH solver, and I found a way how to write complementarity conditions. I use pyomo.mpec and ComplementarityList ...

**1**

vote

**2**answers

26 views

### Removing specific equation from GAMS

I am working with the software, GAMS, and would appreciate some insight in a problem I am facing.
Assume that we have the following structure (grossly simplified for exposition):
Sets
i ...

**0**

votes

**1**answer

61 views

### Logical condition in set (GAMS) - how do this in pyomo?

I'm passing code from Gams to pyomo and I don't know if this option to access an index has in python.
In gams:
k purifiers /PSA4241, PSA241, PSA241A, PSA3241, NEW/
oldk(k) = yes$(ord(k) le 4) ; ...

**0**

votes

**0**answers

16 views

### Model for scheduling surgeries

I am developing a model in GAMS to schedule surgeries. I think I am not getting the right results and think some equations may not be well formulated. Bellow you can find the entire model I developed. ...

**1**

vote

**0**answers

26 views

### Solve multi-objective problem in Gurobi by using epsilon-constraint method

I am trying to solve my multi-objective problem in Gurobi using the epsilon-constraint method.
I didn't find any sample code in Gurobi(python). I am new to gurobi and have no experience in coding. ...

**-1**

votes

**1**answer

56 views

### How to limit the count of nonzero variables in GAMS mixed-integer nonlinear programming?

The background of the problem:
There are 25 candidates on Neo blockchain that receive votes. Every voter except me has voted.
The candidates ranked 1st to 7th each will give 200 dollars, ...

**0**

votes

**1**answer

41 views

### Extract data to update model parameters and solve maximization problem in GAMS

I have several farmers and I would like to conduct optimization (profit maximization) for each of them in GAMS. I can do this for a single farmer, so my problem is how to iteratively make it works for ...

**0**

votes

**1**answer

59 views

### General problems

Bellow you can find the entire model I developed. I think my main issues lie in:
eq08:it is supposed to only allow one surgery to be scheduled during the entire duration of said surgery. For example, ...

**0**

votes

**1**answer

42 views

### I used Gams, it gives an error in the code

I coded that model using gams, but when I pressed run, it an gives error on line 42.(line starting with cons2(i)) Before that it was giving an error in the last two lines. The last two lines are "...

**1**

vote

**0**answers

19 views

### Any automatic code formatting tool for GAMS (stand-alone or IDE-integrated)?

I am mainly working in the python ecosystem and am used to automatic code formatters (e.g. Black).
For a new project I have to work with GAMS and a lot of legacy GAMS code.
The GAMS code is by ...

**0**

votes

**2**answers

54 views

### How do set up something similar to GAMS' circular indexing for Pyomo

I'm working on a pyomo constraint that has a rule in the first loop to do some calculation based on the last loop. So for T = 24, each loop is:
def const1(model,t):
return model.x[t] == model.x[t -...

**0**

votes

**2**answers

75 views

### Need to write a set of linear equations for following condition:

I have three variables : A, B, C.
I want to write a set of linear equations such that
X = 1 if atleast 2 of A,B,C are ones.
X= 0 if only one of A,B,C is one.
X = 0 if all of them are zero.
A,B and C ...

**0**

votes

**0**answers

14 views

### variable definition problem over sets in GAMS

My problem is with the definition of variable 'ds' used in equation 1. Eq 1 runs for each line. And each line has ns (ns is a parameter) number of steps. Variable 'ds' should be defined for each step ...

**0**

votes

**1**answer

25 views

### How do I convert if statement to linear equation?

I wanna convert this if statement to linear equation.
for i,j -> 1 to n
if D[i]>D[j] and f[i] > s[j] then w[i]+=c[j]
The line below is what has come to my mind so far, but I do not know how ...

**0**

votes

**1**answer

19 views

### Calculation with mapping in GAMS

Consider the following data:
set i / 1 * 4 /
tid / 2019, 2020 /
iagg / 1 * 2 /;
parameter t(i,tid),tagg(iagg,tid);
t(i,tid) = uniform(0,1);
set itoiagg(i,iagg) /
1.1
2....

**0**

votes

**0**answers

24 views

### Reading an excel file from gams by creating a .inc file

I am trying to read an excel file from gams using the following code:
set i /1*10/;
Parameter x(i)/
$call xls2gms r=a1:j1 i=Data1.xlsx o=xi.inc
$include xi.inc
/;
However .inc file is generated and ...

**0**

votes

**1**answer

82 views

### gdx file is not created when trying to export data from excel to gams

I'm trying to export data from Excel to GAMS and I'm using the next code for this aim:
Set c row labels /c1*c10/
x column labels /x1*x2/;
Parameter d(c,x);
$call GDXXRW Data.xlsx trace=3 par=d ...

**0**

votes

**1**answer

16 views

### Error in defining sets and indexes as alias

I'm trying to calculate the euclidean distance between some points. The coordinates of the points are denoted by x(i) and y(i), and the indices i and j are alias. For this I use the following code:
i &...

**1**

vote

**1**answer

21 views

### Defining a dynamic set in GAMS, General Algebraic Modeling System

I want to define a dynamic set in GAMS, General Algebraic Modeling System. For example, consider the next line:
Set i "Customers" /1*100/;
Sometimes it will be /1x50/ and sometimes /1x100/. ...

**0**

votes

**1**answer

29 views

### create equation summing over variables with shifting index gaps in GAMS

I want to add a constraint in gams that sums over a variable that takes indices with a shifting gap between them. For example, I have a set of hour (h) in the year. My variable is g(h). My desired ...

**0**

votes

**0**answers

36 views

### GAMS I need help on a set covering problem

I am trying to solve a set covering problem in GAMS. There are particular amount of nodes. I know the distance between the nodes. If the distance larger than 500m, I don't connect the nodes. I want to ...

**0**

votes

**1**answer

43 views

### GAMS if-else syntax

if (a(i,j) gt 0,
z(i,j) eq 0;
else
z(i,j) eq 1;
);
equations
kapasite_asker(i)
kapasite_silah(i,k)
talep_asker1(j)
talep_asker2(j)
talep_silah1(j)
talep_silah2(j)
atama_asker(i)
atama_silah(i)
...

**1**

vote

**1**answer

59 views

### Set up gams module for python on Linux

I'm sure this problem is pretty basic but this is my first time trying to run gams via python on Linux so I'd appreciate some help. My problem seems to be that I cannot properly link the GAMS ...

**0**

votes

**1**answer

30 views

### When I try to write a variable including different sets I get an error. How can I solve Gams Error 198?

I get an error when I try to use a variable as v(i+1 , j+1).
How can I write v(i+1 , j+1) in GAMS code if I defined only v(i , j) as a variable before?
Related parts in the code are as following:
...

**0**

votes

**0**answers

16 views

### reason that GAMS read 10 out of 11 variables from my model if they all have the same format?

I'm running a Computable General Equilibrium Model supported by a Social Accounting Matrix. I have a subset of 11 variables, of which GAMS doesn't read one, I have tried to change the format of my ...

**0**

votes

**1**answer

23 views

### GAMS- manipulating expression within a loop

I have a matrix, of dimension, i rows and j columns, a specific element of which is called x(i,j), where say i are plants, and j are markets. In standard GAMS notation:
Sets
i canning plants /...

**0**

votes

**1**answer

13 views

### GAMS - matrix row operations

I have the following matrix in GAMS (call it a matrix x with rows
i and columns j):
I wish to transform this by summing elements in the same column from
row 2 and row 1, and then setting row 2 to 0:
...

**0**

votes

**1**answer

24 views

### GAMS translated nonlinear objective function looks different than defined objective

I am studying the batchdes.lst file for MINLP model batchdes in GAMS library. The objective function is
Defining objective function obj.. cost =g= sum(j, alpha(j)*(exp(n(j) + beta(j)*v(j))));
However, ...

**0**

votes

**0**answers

45 views

### How to write piecewise function code in GAMS?

I am fairly new to GAMS coding and would like to know how can I write code for this fucntion.

**0**

votes

**0**answers

16 views

### How can i use function smax

i have problem about use smax in GAMS model. how can i fixing.
thankyou for ans.
Positive Variable
C(i,k) time in peocess
Cmax(i) max time ;
variable
T(i) T(i)=max(0,Cmax(i) -...

**0**

votes

**1**answer

98 views

### Multiply matrix with vector in GAMS

Consider the following table in GAMS:
Set i /i1*i4 /;
Table a(i,j) 'original matrix'
i1 i2 i3 i4
i1 2 0 0 0
i2 0.272727 2 0....

**0**

votes

**1**answer

18 views

### Calculate specific matrix in GAMS

Consider the following data in GAMS:
Set i / 0*3 /;
Parameters
r(i)
/ 2 0.272727
3 0.8 /
s(i)
/ 2 0.727273
3 0.2 /;
I want to calculate the following matrix (...

**0**

votes

**1**answer

25 views

### Insert parameter value into $evalGlobal in GAMS

Consider the following $SetGlobal:
$setglobal Path MyPath
I use the following code to finding the numbers of characters in 'MyPath':
set Length /%Path%/;
Parameter report(Length,*);
report(Length,'...

**0**

votes

**0**answers

26 views

### How to create multidimensional sets in JuMP/Julia as in GAMS

In GAMS, we can create multidimensional sets as follows
Set i "mining regions" / china, ghana, ee+ussr, s-leone /
n "ports" / accra, freetown, ...

**0**

votes

**0**answers

25 views

### Reading in data with already defined set in GAMS from excel

I am learning how to use GAMS and am having trouble with reading in a single column using an already defined set. I managed to read in a table and it displays as needed. This is what I attempted:
...

**0**

votes

**1**answer

48 views

### Problem with translating characters with tr (POSIX) in GAMS

In GAMS version 33.2.0, I am changing the semi-colons to commas in a csv-file 'file.csv' because GAMS demands commas as separators. Then I want to transfer the content of the csv-file into a table in ...

**0**

votes

**0**answers

31 views

### Writing hyperbolic inequalities as second order conic inequalities in GAMS

I coded a GAMS model that has hyperbolic inequalities and GAMS can solve it. However, when I transform the hyperbolic inequalities likesqr(th(j)) =l= u(j)*f(j); to second order conic inequalities as 2*...

**0**

votes

**0**answers

21 views

### Logic programming in GAMS

How would I be able to perform in GAMS syntax the logical input p implies no q (p => ~q)? The context is that I have a product in a sequence where another product can not be right after the first ...

**0**

votes

**1**answer

99 views

### GAMS compile to GDX drops column with all zero values

NOTE: Update (but not solved) Below
In my use case for GAMS I wish to define a collection of static variables in a .gdx file rather than in the main model.gms script. This is not an issue unless I ...

**0**

votes

**0**answers

31 views

### Error while solving bilevel Optimization using GAMS with EMP

I am solving bilevel nlp optimization with one follower using GAMS. I am getting this error while creating emp.info while using code given below: -
Code: -
$echo bilevel x(i,j) min of * eq1 eq2(j) eq3(...

**0**

votes

**0**answers

125 views

### How to code particle swarm optimization with constraints in MATLAB?

I have a GAMS code that represent a mathematical model which depends delay (i,p) for each job i and the period of day p. So, I have indices for represent delay and objective is minimizing of summing ...

**0**

votes

**0**answers

41 views

### Writing equation for the last element in a set in GAMS

I'm trying to model a job shop scheduling problem. In the model, L(i,j) represents the set of processes j for each job i. Each i has a different set of processes in different orders. In some of the ...

**0**

votes

**1**answer

242 views

### GAMS - writing output to excel file using GDX

I am in the midst of exporting data from GAMS to excel. As such, I am using the GDX utilities.
Say that I have two variables, x and y, defined over the set i. The set i={1,2,3,4}. As such, x(i) and y(...

**0**

votes

**1**answer

33 views

### Will GAMS optimize the default parameters of Solver?

I have a MILP problem. I use CBC solver to solve it. If I call CBC through GAMS, the computation time will be short. But when I solve it directly using CBC.exe, it takes too much time. In both cases, ...

**0**

votes

**0**answers

44 views

### Struggling in converting gams model to pyomo - objective function giving syntax error

I would like to write the following function in Pyomo but I am struggling.
I wrote it in GAMS as follows it works:
objectivefunction.. NetP =e= sum(s$(Sp(s)), sum(n$(ord(n)=card(n)), Ps(s)*(ST(s,n) + ...

**1**

vote

**0**answers

91 views

### How can I transfer my results from GAMS to Python?

I built my first GAMS code, but I don't know how to transfer the results from the lst file to Python in order to process. If anyone could help with the issue I would be very grateful. For example, for ...

**0**

votes

**0**answers

18 views

### Is there a GAMS function that returns related sets?

guys! Does someone know how to create the following variable for a GAMS model?
Sets
p periods /p1*p4/
sp sub-periods /sp1*sp8/
subp(p,sp) ...

**0**

votes

**1**answer

66 views

### Passing a variable as a parameter for a new model in GAMS

I'm writing a program where I have two mathematical models that are solved sequentially in a way that the variable X7(f,p) from the first model becomes the parameter rwdemand(f,p) to the second.
Main ...

**1**

vote

**1**answer

29 views

### Write system date and time as string to gdx

I want to store the system date and time as a string to gdx when executing a script, preferably with a custom format.
I tried the following:
parameter
exec_date execution date
exec_time ...