[Cmpl] Question about readcsv and multi-dimension arrays

Mike Steglich mike.steglich at berlin.de
Thu Sep 12 15:22:00 EDT 2013


Hi Michael,

Welcome to the CMPL user group!

If you want to specify sets within a parameters section you have to use the keyword set as follows:

    parameters:
        plants := set("seattle", "san_diego");
        markets := set("new_york", "chicago", "topeka");

After these expressions you can read the data with the csv file 
        r[plants, markets] := readcsv("r.csv");

and do what you want with the date; e.g. print the values:
	{i in plants, j in markets: echo r[i,j]; }


I would like to propose that you use a cmplData file instead a csv file because this file format is more flexible.

The formulation of the cmplData file r.cdat for your example looks like follows:
	%plants set < seattle san_diego >
	%markets  set <new_york chicago topeka>

	%r[plants, markets] < 	2.5 1.7 1.8 
						2.5 1.8 1.4 > 

You can read the sets and the parameter array with the CMPL header entry %data:

	%data r.cdat 
   	parameters:
		{i in plants, j in markets: echo r[i,j]; }

Cheers,

Mike



Am 12.09.2013 um 20:22 schrieb Michael Bond:

> I'm just getting started with CMPL and have what seems like a rather basic question. Given the following CMPL model how what should the csv for r be formatted:
> 
>     parameters:
>         plants := "seattle", "san_diego"
>         markets := "new_york", "chicago", "topeka"
>         r[plants, markets] := readcsv("r.csv");
> 
> Using the following in r.csv:
> 
> 2.5,1.7,1.8
> 2.5,1.8,1.4
> 
> I get the following errors:
> 
> error (interpreter): file transport.cmpl line 9: Count of elements for the 1. index of 'r' is wrong
> error (interpreter): file transport.cmpl line 9: Count of elements for the 2. index of 'r' is wrong
> 
> Using the following in r.csv:
> 
> new_york,chicago,topeka
> seattle,2.5,1.7,1.8
> san_diego,2.5,1.8,1.4
> 
> I get the following errors:
> 
> error (interpreter): file transport.cmpl line 9: Count of elements for the 1. index of 'r' is wrong
> error (interpreter): file transport.cmpl line 9: Count of elements for the 2. index of 'r' is wrong
> error (interpreter): file transport.cmpl line 9: Count of elements for the 2. index of 'r' is wrong
> error (interpreter): file transport.cmpl line 9: Count of elements for the 2. index of 'r' is wrong
> 
> I've tried a number of other variations with no success. I've seen the readcsv examples that use an unbounded array (r[,]) but for would prefer to use bounded arrays. Any help would be welcome.
> This email is intended only for the use of the individual(s) to whom it is addressed. If you have received this communication in error, please immediately notify the sender and delete the original email._______________________________________________
> Cmpl mailing list
> Cmpl at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cmpl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20130912/451951fb/attachment.html>


More information about the Cmpl mailing list