Originally posted by: char507
Hi,
I am writing a C# program to open an OPL CPLEX model, populate the model with data, and interpret the results. I'm having a problem finding the easiest or most efficient way to populate a large 2D array with zeros and a few ones here and there. The array is defined in the OPL .mod file as such: "int X
rowcolumn=...;"
I found the following code in the CustomDataSource example:
// initialize a 2-dimension int array 'a2DIntArray'
handler.StartElement("a2DIntArray");
handler.StartArray();
for (int i = 1; i <= 2; i++)
{
handler.StartArray();
for (int j = 1; j <= 3; j++)
handler.AddIntItem(i * 10 + j);
handler.EndArray();
}
handler.EndArray();
handler.EndElement();
This seemed like a decent method for adding the data I need to add. However, I tried to write some code to output this element once it was inserted into the OPL model so I could understand the order that the code was inserting the numbers (i.e. rows at a time or columns at a time) but I couldn't figure out how to do it. Could someone possibly provide me a code snippet that would output this array in the proper order?
Secondly, is there a more efficient way of populating a large matrix of mainly zeros with ones in a few specific places? I'm not very familiar with the use of Tuples or more complicated objects so I have stayed around from those at this point. However, it would be nice to set all values in the matrix to zero and then simply say something like X
1,10 = 1; X
3, 21 = 1; etc.
I'm sorry to ask such a seemingly basic question but any help would be greatly appreciated.
- Charlie
#DecisionOptimization#OPLusingCPLEXOptimizer