Topic
• 2 replies
• Latest Post - ‏2013-12-04T17:22:57Z by MarekGrzes
MarekGrzes
10 Posts

# Pinned topic What is the easiest way to define a sparse matrix in an OPL data file?

‏2013-12-04T14:47:17Z |

Hello,

I am formulating a MIP problem in OPL where input data (including several matrices) are in the data file *.dat. It looks that I can easily define dense matrices in OPL data files, e.g.:

Capacity = [ 18209, 7692, 1333, 924, 26638, 61188, 13360 ];

But, what about sparse matrices. I know that AMLP allows for such things:

param x[1, 1] -1.0
[1, 2] -0.8
[1, 5] -1.0
[2, 1] -1.0
[2, 2] -0.1

where only non-zero entries are provided. Is it possible to do something like that in OPL? Can I do it without tuples?

Cheers,

Marek

• AlexFleischer
2971 Posts

#### Re: What is the easiest way to define a sparse matrix in an OPL data file?

‏2013-12-04T15:36:34Z

Hi,

you have an example at

### Specifying pairs

An array can also be initialized by specifying pairs (index, value), as in the declaration:

/* .mod file */
int a[Days] = ...;
/* .dat file */
a = #[
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
]; #

regards

Updated on 2013-12-04T15:38:12Z at 2013-12-04T15:38:12Z by AlexFleischer
• AlexFleischer
2971 Posts

#### Re: What is the easiest way to define a sparse matrix in an OPL data file?

‏2013-12-04T15:36:34Z

Hi,

you have an example at

### Specifying pairs

An array can also be initialized by specifying pairs (index, value), as in the declaration:

/* .mod file */
int a[Days] = ...;
/* .dat file */
a = #[
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
]; #

regards

Updated on 2013-12-04T15:38:12Z at 2013-12-04T15:38:12Z by AlexFleischer
• MarekGrzes
10 Posts

#### Re: What is the easiest way to define a sparse matrix in an OPL data file?

‏2013-12-04T17:22:57Z

Hi,

you have an example at

### Specifying pairs

An array can also be initialized by specifying pairs (index, value), as in the declaration:

/* .mod file */
int a[Days] = ...;
/* .dat file */
a = #[
"Monday": 1,
"Tuesday": 2,
"Wednesday": 3,
"Thursday": 4,
"Friday": 5,
"Saturday": 6,
"Sunday": 7
]; #

regards

That's cool. Pairs seem to generalise to more dimensions too.

a = [[0,10],[0,0]];

can be defined as

a = #[
1: #[2: 10]#
]#;

In  the meantime, I realised that tuples have some adventages as well.

Cheers,

Marek