csv provider loop

27 views
Skip to first unread message

Wiet Mazairac

unread,
Apr 28, 2019, 6:02:26 PM4/28/19
to AIMMS - The Modeling System
Hi,

I am looking for an example of how to put the next few lines of code in a loop...

FolderName := "C:/folder_name/";

dl
::DataTables += {'p_001'} ;

datamap
(dl::dt,dl::idn,dl::cn,dl::dn) := data {
   
( 'p_001', 'aa',     1, 1 ) : "aa",
   
( 'p_001', 'bb',     2, 2 ) : "bb",
   
( 'p_001', 'p_001',     3, 3 ) : "p_001"
};

spCommunicationAttributes
:= {
   
'DataProvider' : csvprov::DataLink,
   
'ContainsHeaders' : "yes"
};

dl
::DataWrite(
   
FolderName,
   
"p_001",
    spCommunicationAttributes
);


This loop should process all varibales and parameters.
Please provide an example.

Thanks!!





Mohan

unread,
May 2, 2019, 5:50:51 PM5/2/19
to AIMMS - The Modeling System
Hello Wiet,

Looks like you want to have each parameter / variable in a separate csv file. You can write a loop for all the identifiers that have the same index domain because the data map requires you to list out the domain sets. See MainExecution in attached example project. I put all the identifiers I want to write out in the declaration section My Parameters and then in s_MyParameters (a subset of the predefined set AllIdentifiers), I used the definition My Parameters * AllIdentifiers. So, s_MyParameters will contain all the identifiers that you want to write. Note that these must have the same index domain, in the same order.

I used an element parameter ep_TableName with range dl::dt and another element parameter ep_IndexDomain1 with range AllIdentifiers. It will be more convenient if you have these element parameters as they will save you from writing more code.

Instead of writing your original datamap, you will write something like this.

datamap(ep_TableName, ep_IndexDomain1, 1, 1) := ep_IndexDomain1;
datamap
(ep_TableName, ep_IndexDomain2, 2, 2) := ep_IndexDomain2;
datamap
(ep_TableName, i_MyParameter, 3, 0) := i_MyParameter;

instead of


datamap
(dl::dt,dl::idn,dl::cn,dl::dn) := data {

   
( 'p_001', 'aa',     1, 1 ) : "aa",
   
( 'p_001', 'bb',     2, 2 ) : "bb",
   
( 'p_001', 'p_001',     3, 3 ) : "p_001"
};

The i_MyParameter is the for loop operator. By using MapName := i_MyParameter, you will write the csv file name with the parameter/variable name. Hope this helps.
CSVLink.7z

Wiet Mazairac

unread,
May 3, 2019, 1:51:44 PM5/3/19
to AIMMS - The Modeling System
After some searching CSVExport (DLL) seems to do exactly that.
How does it compare to your solution?

Mohan

unread,
May 3, 2019, 6:02:32 PM5/3/19
to AIMMS - The Modeling System
Hello Wiet,

The CSVExport DLL will be much easier for you to implement.

I would recommend you to use that instead of my proposed solution using DataLink.

You can still write the for loop in the MyParameters set and write out that particular identifier.
Reply all
Reply to author
Forward
0 new messages