Page 1 of 1

How to define multi-dimensional sets with assigning values

Posted: Thu May 14, 2020 5:37 pm
by Parisa
Hello everybody,
I have the following CSV file, it is like an array with four entries "(i, s, t, f)", in which "i" is the indicator and "s, t, f" are its assigned values.
for this, I have written the next code.

Code: Select all

Sets
         i       /1*300/
         s       /0*23/
         t       /1*24/;
Sets
         x(i,s,t)
/
$ondelim
$include Pairs.csv
$offdelim
/;
But the code gives the result like this;
Image

This is not what I want since values are not accessible.
Thank you for your helps. :)
Pairs.csv
(4.26 KiB) Downloaded 211 times

Re: How to define multi-dimensional sets with assigning values

Posted: Fri May 15, 2020 7:37 am
by bussieck
f is a numeric field, correct? You you need to store this in a parameter not a set:

Code: Select all

Parameter x(i,s,t)
/
$ondelim
$include Pairs.csv
$offdelim
/;
-Michael

Re: How to define multi-dimensional sets with assigning values

Posted: Fri May 15, 2020 5:48 pm
by Parisa
Thank you for your reply.
But if I define it as a parameter, then I cannot use syntaxes such as, "for" or "loop".
Moreover, Would you please give me some hints on How I can define a subset for multi-dimensional sets?

Re: How to define multi-dimensional sets with assigning values

Posted: Sat May 16, 2020 9:20 am
by bussieck
Why not? loop((i,s,t)$x(i,s,t), ...) iterates through the non-zero tuples of x. You can also create a dynamic set from x: set xset(i,s,t); xset(i,s,t) = x(i,s,t); You should invest more in understanding the principles of the language and study the documentation. Then things will be clearer.

-Michael

Re: How to define multi-dimensional sets with assigning values

Posted: Sat May 16, 2020 11:07 am
by Parisa
Thank you.