Re: HELP: Reading table from CSV

2020-12-05 Thread Manuel Castro
Thank you.



How could I then pass the values in the table you suggest into the array  
LoadPowerProfile{i in LoadsCount, j in PeriodsCount}




 On Sat, 05 Dec 2020 13:54:55 + Heinrich Schuchardt 
 wrote 


On 12/5/20 2:11 PM, Manuel Castro wrote: 
> Hi all, 
> 
> First, I would like to thank you for the constant support as you have 
> always addressed my questions very promptly. 
> Second, I would like to ask you a question as I am really stuck on this one. 
> 
> I have defined the following in the code: 
> set LoadsCount; 
> set PeriodsCount; 
> param LoadPowerProfile{i in LoadsCount, j in PeriodsCount}; 
> 
> For the sake of discussion let's assume that "LoadsCount" is 1..100 and 
> "PeriodsCount" is 1..8760 (i.e. hourly values through the year). 
> I now want to fill in my array "LoadPowerProfile" with values. For that 
> I have the following table in CSV (of course this is a stylized table 
> just for you to understand what I am up to). 
 
With the GLPK you cannot read cross-tabulated CSV files. 
 
You should create a table where you have separate columns for load, 
hour, value. 
 
Load,Hour,Value 
1,0,3.4 
1,1,5.7 
... 
100,8760,6.7 
 
Best regards 
 
Heinrich 
 
> 
> Load 
> 1 
> 2 
> (…) 
> 8760 
> Load1 
> 11.98 
> 62.51 
> 
> 99.69 
> Load2 
> 86.39 
> 59.50 
> 
> 25.89 
> (...) 
> 
> 
> 
> 
> Load100 
> 67.98 
> 98.71 
> 
> 31.19 
> 
> 
> How do I read the yellow shaded area into my "LoadPowerProfile" array? I 
> would be thankful if you could give me an example of the statement i 
> should use to read this into "LoadPowerProfile" array. 
> 
> Many thanks in advance for all your support. 
> 
> Kind regards, 
> Manuel. 
>

HELP: Reading table from CSV

2020-12-05 Thread Manuel Castro
Hi all,



First, I would like to thank you for the constant support as you have always 
addressed my questions very promptly.

Second, I would like to ask you a question as I am really stuck on this one.



I have defined the following in the code:
set LoadsCount; 

set PeriodsCount;

param LoadPowerProfile{i in LoadsCount, j in PeriodsCount};



For the sake of discussion let's assume that "LoadsCount" is 1..100 and 
"PeriodsCount" is 1..8760 (i.e. hourly values through the year).

I now want to fill in my array "LoadPowerProfile" with values. For that I have 
the following table in CSV (of course this is a stylized table just for you to 
understand what I am up to). 





Load

1

2

(…)

8760


Load1

11.98

62.51

 

99.69


Load2

86.39

59.50

 

25.89


(...)

 

 

 

 


Load100

67.98

98.71

 

31.19






How do I read the yellow shaded area into my "LoadPowerProfile" array? I would 
be thankful if you could give me an example of the statement i should use to 
read this into "LoadPowerProfile" array.



Many thanks in advance for all your support.



Kind regards,

Manuel.

Help: “current directory” function

2020-12-03 Thread Manuel Castro
Hi glpk wizards,



I wonder if there a kind of function or workaround that returns the directory 
path of where the ‘.mod’ file is??



Basically in the folder where the ‘.mod’ file is, I have created another folder 
called “data” where I have all my input and output CSV data files. I can insert 
this directory path as a string in the GLPK reading CSV file statement. But of 
course if I change the directory of the project then, I have to go to the 
‘.mod’ file and rewrite the directory path which is very inconvenient. 



So, is there a function/workaround that can return the directory path of the 
‘mod’ file?



Many thanks for your help.



Kind regards,

Manuel.

Help “current directory” function

2020-12-02 Thread Manuel Castro




Hi glpk wizards,I wonder if there a kind of function or workaround 
that returns the directory path of where the ‘.mod’ file is??Basically in the 
folder where the ‘.mod’ file is, I have created another folder called “data” 
where I have all my input and output CSV data files. I can insert this 
directory path as a string in the GLPK reading CSV file statement. But of 
course if I change the directory of the project then, I have to go to the 
‘.mod’ file and rewrite the directory path which is very inconvenient. So, is 
there a function/workaround that can return the directory path of the ‘mod’ 
file?Many thanks for your help.Kind regards,Manuel.










Help: read single value from CSV

2020-11-28 Thread Manuel Castro
Hi there,



What does the syntax statement look like to read a single value from the CSV 
file?

My CSV has the following:

RowIndex   Capacity

   1                   33



I read it as follows:

param Z {i in I};

table tab_stream IN "CSV" "stream.csv" : [RowIndex], Z ~ Capacity;



I am only interested in the column 'Capacity', i.e. in the value 33.

More importantly, I don't need Z to be an array. I want Z to be a scalar i.e. 
param Z;


How do I represent this in the read statement of the CSV?



Many thanks.



Kind regards,

Manuel. 

Help: read from txt files

2020-11-26 Thread Manuel Castro
Hi there,



Is it possible to get GLPK to read/write data from/to text files?


If yes:

what is the syntax statement one should use for that purpose?

what is the format the input data in the text file should be in?




Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel. 

Help: Switching between different objective function

2020-11-26 Thread Manuel Castro
Hi there,



I am wondering how I can use an if statement to switch between different 
objective functions.

For example, how do I represent the following:





If (StatusFlag_X == 1 && StatusFlag_Y == 0) then

  minimize cost: sum{i in I, j in J} c[i,j] * x[i,j];

end if



If (StatusFlag_X == 0 && StatusFlag_Y == 1) then

  minimize cost: sum{i in I, j in J} c[i,j] * x[i,j] + d[i,j] * Y[i,j];

end if



Both are mutually exclusive, i.e. either you do one or the other, i.e. both 
objective functions will never be activate at the same time



This is what I used to do in "mosel" language from FICO Xpress (I don't have a 
license anymore so I am discovering GLPK ). How can I do this in GLPK language? 
What's the workaround that we can use for this?



Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel. 

Re: Help: Switch constraints on or off

2020-11-24 Thread Manuel Castro




Hi Andrew,Thank you for the prompt reply.What do you mean by C 
prepocessor?? Apologies, I know how to program but that’s pretty much it... 
On Tue, 24 Nov 2020 19:42:10 +  m...@gnu.org wrote On 
Tue, 2020-11-24 at 18:59 +, Manuel Castro wrote: > Hi there, >  > I am 
wondering how I can use an if statement to turn a constraint on > or off. > For 
example in my problem I have the following constraint: >  > subject to linctr14 
{i in PeriodsCount: i == 1}: StorageEnergy[i] = > (StorageStateCharge * 
StorageEnergyRating + ((StorageEfficiencyCharge > * (StoragePowerCharge[i])) - 
((StoragePowerDischarge[i]) / > StorageEfficiencyDischarge))); >  > Now, I only 
want to consider storage in my problem if an object > storage actually exists. 
> For that, I would have a StorageStatusFlag which if equal to "1" then > I 
would consider the constraint in my problem. > For example:  >  > If 
(StorageStatusFlag == 1) then >     subject to linctr14 {i in PeriodsCount: i 
== 1}: StorageEnergy[i] > = (StorageStateCharge * StorageEnergyRating + > 
((StorageEfficiencyCharge * (StoragePowerCharge[i])) - > 
((StoragePowerDischarge[i]) / StorageEfficiencyDischarge))); > end if >  > This 
is what I used to do in "mosel" language from FICO Xpress (I > don't have a 
license anymore so I am discovering GLPK ). How can I do > this in GLPK 
language? What's the workaround that we can use for this?   You could use the C 
preprocessor.   >  > Many thanks in advance for your help. It's really 
appreciated. >  > Kind regards, > Manuel.  >  








Change Path Input/Output file

2020-11-24 Thread Manuel Castro
Hi there,



I am currently using gusek as an IDE to model and run GLPK.

I use the following statement to read from CSV file.



table tab_plant IN "CSV" "plants.csv" : I <- [plant], a ~ capacity;



This assumes that the file is placed in the same directory where the glpk 
solver is.

How can I place my CSV file in a different directory and tell glpk to read it 
from there? How do I add the path on my model syntax? 


Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel. 

Help: Switch constraints on or off

2020-11-24 Thread Manuel Castro
Hi there,



I am wondering how I can use an if statement to turn a constraint on or off.

For example in my problem I have the following constraint:



subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] = 
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge * 
(StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) / 
StorageEfficiencyDischarge)));



Now, I only want to consider storage in my problem if an object storage 
actually exists.

For that, I would have a StorageStatusFlag which if equal to "1" then I would 
consider the constraint in my problem.

For example: 



If (StorageStatusFlag == 1) then

    subject to linctr14 {i in PeriodsCount: i == 1}: StorageEnergy[i] = 
(StorageStateCharge * StorageEnergyRating + ((StorageEfficiencyCharge * 
(StoragePowerCharge[i])) - ((StoragePowerDischarge[i]) / 
StorageEfficiencyDischarge)));

end if


This is what I used to do in "mosel" language from FICO Xpress (I don't have a 
license anymore so I am discovering GLPK ). How can I do this in GLPK language? 
What's the workaround that we can use for this?



Many thanks in advance for your help. It's really appreciated.



Kind regards,

Manuel.