Topic
• 4 replies
• Latest Post - ‏2012-11-07T12:49:51Z by arguen
arguen
23 Posts

# Pinned topic help with min function

‏2012-11-06T11:26:49Z |
Hello,
I need help with min function.
I want to find min value of Tijv[i][j][v] over j for all i and v and assign these minima to a new matrix: MinTj[i][v]
My following code gives "Scripting parser error".

``````

int Tijv[N][N][V] =...;
//Assigning travel times

int MinTj[N][V];     execute MINJ
{

for (var v in V)
{

for (var i in N)
{ MinTj[i][v] = ( min(j in N) Tijv[i][j][v] );
// gives error - Scripting parser error: missing ')' - on this line
}
}
}```
```
Updated on 2012-11-07T12:49:51Z at 2012-11-07T12:49:51Z by arguen
• GGR
83 Posts

#### Re: help with min function

‏2012-11-06T15:25:18Z
Hi

You cannot use the construct "min (j in 1..N)" in the script. For initializing the array MinTj, you can directly use the modeling language.

``````

int N = 10;

int V = 5;

int Tijv[i in 1..N][j in 1..N][v in 1..V] = v*(1 + 10*((i < j) ? j - i : i - j));
//Assigning travel times

int MinTj[i in 1..N][v in 1..V] =  min (j in 1..N) Tijv[i][j][v];```
```

cheers
• arguen
23 Posts

#### Re: help with min function

‏2012-11-07T07:17:22Z
• GGR
• ‏2012-11-06T15:25:18Z
Hi

You cannot use the construct "min (j in 1..N)" in the script. For initializing the array MinTj, you can directly use the modeling language.

<pre class="jive-pre">``` int N = 10; int V = 5; int Tijv[i in 1..N][j in 1..N][v in 1..V] = v*(1 + 10*((i < j) ? j - i : i - j)); //Assigning travel times int MinTj[i in 1..N][v in 1..V] = min (j in 1..N) Tijv[i][j][v];``` </pre>

cheers
It helped.
But I have one more question, if you don't mind:
How can I understand which functions/keywords can be used in script and which can be used in modeling language or both and syntax difference.
It is not clear to me from the manual.
Thank you again.
• GGR
83 Posts

#### Re: help with min function

‏2012-11-07T11:27:35Z
Hi

When using OPL, you manipulate two different languages:

The modeling language is a language for math and constraint programming modeler. It has some specific features tuple, tupleset, jointures on tupleset in all, min, max, sum and forall instruction. For a concise introduction you have the book <<The OPL Optimization Programming Language>> by Pascal van Hentenrick. It suufices for creating all array you need as soon as they are indexed by tupleset and use already initialized array of constant, expressions, constraints, and variables.

The codes in execute (or main) blocks are JavaScript code. You can easily find JavaScript tutorials on the web. The specific JavaScript extensions for OPL is in the online documentation. Note that there is a Java API for OPL that is a similar API than the one in JavaScript. It should be used only for data cleaning and reorganization from the database, outputs and multiple models applications.

Apart the online help, you can access some tutorial documents at http://www-01.ibm.com/software/integration/optimization/cplex-optimization-studio/

I can hardly say more than practices and distributed samples look for training.
Hope that helps
• arguen
23 Posts

#### Re: help with min function

‏2012-11-07T12:49:51Z
• GGR
• ‏2012-11-07T11:27:35Z
Hi

When using OPL, you manipulate two different languages:

The modeling language is a language for math and constraint programming modeler. It has some specific features tuple, tupleset, jointures on tupleset in all, min, max, sum and forall instruction. For a concise introduction you have the book <<The OPL Optimization Programming Language>> by Pascal van Hentenrick. It suufices for creating all array you need as soon as they are indexed by tupleset and use already initialized array of constant, expressions, constraints, and variables.

The codes in execute (or main) blocks are JavaScript code. You can easily find JavaScript tutorials on the web. The specific JavaScript extensions for OPL is in the online documentation. Note that there is a Java API for OPL that is a similar API than the one in JavaScript. It should be used only for data cleaning and reorganization from the database, outputs and multiple models applications.

Apart the online help, you can access some tutorial documents at http://www-01.ibm.com/software/integration/optimization/cplex-optimization-studio/

I can hardly say more than practices and distributed samples look for training.
Hope that helps
Absolutely helped.