gams-math

How to add a condition to a variable - GAMS

情到浓时终转凉″ 提交于 2020-06-14 08:34:13
问题 In the model I'm trying to build, I have a variable defined as: Variables x(i,j) number of motors produced in month i to be delivered in month j ; In that variable, j must always be equal or greater than i for it to make sense (you can't produce something in this month to be delivered in the previous month). However, I have no clue as to how I can properly model this. I've searched and couldn't find an easy solution to this. Any ideas? 回答1: You should use "variables with limited domains" for

loop in GAMS for scenario generation in excel

十年热恋 提交于 2020-05-13 07:50:47
问题 I have an optimization model and I try to solve this model for different input files which I exactly call as "solve the model under different scenarios". For that reason, I need a loop to read the data from excel for each different sheet. Let me make myself clear: For example, in the image below we have a data with 4 scenarios and the sheet names are increasing one by one for each scenario This data has to be read as a table for each scenario, like in the excel file. I try to read the data

How to set upper and lower bounds for each element in a set?

断了今生、忘了曾经 提交于 2020-02-02 13:35:06
问题 I am creating a GAMS model to solve a simple maximization problem. I have a set J with 3 elements (1,2,3) and a variable x(J) that encompasses all the elements. I am wondering if there is a way in GAMS to set a lower bound of 0 and upper bound of 3 to each element in the set without having to set each element bound individually and without using the positive variable keyword for the lower bound. I have tried using x.lo =e= 0 and x.up =e= 3 but none of these are working. I am guessing I am not

How to set upper and lower bounds for each element in a set?

纵然是瞬间 提交于 2020-02-02 13:31:37
问题 I am creating a GAMS model to solve a simple maximization problem. I have a set J with 3 elements (1,2,3) and a variable x(J) that encompasses all the elements. I am wondering if there is a way in GAMS to set a lower bound of 0 and upper bound of 3 to each element in the set without having to set each element bound individually and without using the positive variable keyword for the lower bound. I have tried using x.lo =e= 0 and x.up =e= 3 but none of these are working. I am guessing I am not

GAMS Display style

本秂侑毒 提交于 2019-12-24 04:51:34
问题 How do I display a text in GAMS? For example: in MATLAB I can use disp('MATLAB'), then I will get the output as MATLAB. Is it possible to have like this in GAMS. In fact, I am new with GAMS environment. Regards 回答1: display "Hi, warning message here!" ... should work. This will appear in your .LST file, which you should get familiar with reading for debugging purposes. 回答2: There are actually two ways: $log "text to display" if you want it to appear during the compilation phase (and shows

Generate 100 data randomly, or select if it is possible

纵然是瞬间 提交于 2019-12-20 05:57:27
问题 I want to test my model , I need to test it in some data , I want to generate data , in fact I want to have 125 different parameter from 0 to 10000. For example , in below we have 4 different parameter ,from 1 to 300. Set I/0*300/; Parameter MyParameter; MyParameter /4 1,10 1,42 1,87 1/; I don't want to do this by hand. Is there any method that I generate it automaticly. another way asking: how can Select 4 random element of a set ' I' , without repetition? 回答1: Try this: Set I /0*300/ picks

How to import data from multiple excel sheets in GAMS using loops?

╄→гoц情女王★ 提交于 2019-12-12 02:42:48
问题 I want to import the data for a three-dimensional parameter p(i,j,k) that is stored in in k excel sheets but GAMS does not let me use dollar control statements in loops. Is there any way to do that using loops or other flow control statements like 'for' or 'while'? I need to do something like this but it is seemingly impossible: loop(k, $call gdxxrw Data.xlsx par=temp rng=k!A1:Z20 rdim=1 cdim=1 $gdxin Data.gdx $load temp $gdxin p(i,j,k)=temp(i,j); ); 回答1: Suppose each sheet looks like: (only

Display only something

有些话、适合烂在心里 提交于 2019-12-11 16:59:29
问题 can we have the display command with certain conditions , For example, if we want to just print things their value are bigger than 7 . in other word how can we have Display $( x.val> 7) In general, is it possible to have condition on display command? 回答1: Yes, you can use the $ condition on a Display statement like in any, e.g., assignment statement: Scalar x /2/; Display$(x>3) 'X is greater than 3'; Display$(x>1) 'X is greater than 1'; 来源: https://stackoverflow.com/questions/51783645/display

In GAMS, what is the difference between variables and parameters?

泄露秘密 提交于 2019-12-11 12:18:10
问题 In GAMS, what is the difference between variables and parameters? In which cases is one of them better to use than the other one? 回答1: Short explanation Parameters are used for introducing data into the model. This data can be used in equations and will not be affected by the optimisation. Mathematically, you may think of a constant. (Decision) Variables are 'variable' during the optimisation. The value of a variable in the optimum is reported after the optimisation has finished. Mnemonic

How Display some of 2 dimension parameter?

可紊 提交于 2019-12-11 06:45:48
问题 I have a parameter t(i,j) , and set i,j /1*100/ , I want to display only positive t(I,j) . My try Display$(t(I,j)>0), t; I read following answer too Display only something When I write my command like abow answer , I have error " uncontrolled set entered as constant " What code should I write? Thanks & Best 回答1: The Display statement with with a symbol will always show the whole symbol. The $ condition you saw in the other post, can only be used to decide, if it should be displayed completely