[Cmpl] Question about readcsv and multi-dimension arrays

Michael Bond mbond at videologygroup.com
Thu Sep 12 15:49:22 EDT 2013


Oh right, my example should have been set(...) but the question is still the same, I can't get r[plants,markets] := readcsv("r.csv") to work. I've tried a variety different orders to the data and none seem to parse correctly.

I have managed to successfully use .cdat and even include a separate cmpl file. I'll probably end up using cmpl due to the fact that the grouping is more explicit but would still like to get a sample .csv working.

As a followup question, what would a three-dimension .csv look like, for instance adding time to r?

________________________________
From: Mike Steglich <mike.steglich at berlin.de>
Sent: Thursday, September 12, 2013 3:22 PM
To: Michael Bond
Cc: cmpl at list.coin-or.org
Subject: Re: [Cmpl] Question about readcsv and multi-dimension arrays

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<mailto:Cmpl at list.coin-or.org>
http://list.coin-or.org/mailman/listinfo/cmpl

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20130912/f7c9802a/attachment.html>


More information about the Cmpl mailing list