Pinned topichow to access the types of inerval variables in flow control or postprocess
20121025T06:20:14Z

Answered question
This question has been answered.
Unanswered question
This question has not been answered yet.
Hi, how to access the types of inerval variables in sequence variable in flow control or postprocess script?
For example, in a flow control, I have solved a CP model, and want to get the types of inerval variables vbtasks in sequence variable bs, I write the following script, it doesn't work.
for(k=1; k<=oplmodel.m; k++)
//berth num
for(i=1; i<=oplmodel.n; i++)
//ship num
if (typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0) != 0 ) tox[k][i][opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0)] = 1;
Then, I add prefix opl. to typeOfNext, still does't work. Any idea?
for(k=1; k<=oplmodel.m; k++)
//berth num
for(i=1; i<=oplmodel.n; i++)
//ship num
if (opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0) != 0 ) opl.tox[k][i][opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0)] = 1;
Hi, how to access the types of inerval variables in sequence variable in flow control or postprocess script?
For example, in a flow control, I have solved a CP model, and want to get the types of inerval variables vbtasks in sequence variable bs, I write the following script, it doesn't work.
<pre class="jivepre">
for(k=1; k<=oplmodel.m; k++)
//berth num
for(i=1; i<=oplmodel.n; i++)
//ship num
if (typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0) != 0 ) tox[k][i][opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0)] = 1;
</pre>
Then, I add prefix opl. to typeOfNext, still does't work. Any idea?
<pre class="jivepre">
for(k=1; k<=oplmodel.m; k++)
//berth num
for(i=1; i<=oplmodel.n; i++)
//ship num
if (opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0) != 0 ) opl.tox[k][i][opl.typeOfNext(cpmodel.bs[k], vbtasks[1][i], opl.n+1, 0)] = 1;
</pre>
Re: how to access the types of inerval variables in flow control or postprocess
20121025T11:45:29Z
This is the accepted answer.
This is the accepted answer.
Hi,
In the second example, you specify opl.tox and to my knowledge it is not an opl object field. Is it actually what you mean?
Could you please provide the error messages generated by OPL?
A short model would help us to provide an explanation,
In the second example, you specify opl.tox and to my knowledge it is not an opl object field. Is it actually what you mean?
Could you please provide the error messages generated by OPL?
A short model would help us to provide an explanation,
In the manual, I see "Using the Opl namespace you can have access to OPL functions". So I tried opl.typeOfNext(). But it reports error: unknown variable 'opl' .
Is there a way to know the type of a interval variable in a sequence variable in postprocess script?
In the manual, I see "Using the Opl namespace you can have access to OPL functions". So I tried opl.typeOfNext(). But it reports error: unknown variable 'opl' .
Is there a way to know the type of a interval variable in a sequence variable in postprocess script?
In the manual, I see "Using the Opl namespace you can have access to OPL functions". So I tried opl.typeOfNext(). But it reports error: unknown variable 'opl' .
Is there a way to know the type of a interval variable in a sequence variable in postprocess script?
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; execute
{ writeln(
"p " + p);
for (var i=1; i<=n; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(p,A[i],0));
}
please use "Opl" to refer to the opl object.
I hope this helps.
Renaud
Dear qtbgo
The following example works fine:
<pre class="jivepre">
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; execute
{ writeln(
"p " + p);
for (var i=1; i<=n; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(p,A[i],0));
}
</pre>
please use "Opl" to refer to the opl object.
I hope this helps.
The following example works fine:
<pre class="jivepre">
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; execute
{ writeln(
"p " + p);
for (var i=1; i<=n; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(p,A[i],0));
}
</pre>
please use "Opl" to refer to the opl object.
I hope this helps.
Additionally, you have to specify at least 3 parameters to "typeOfNext". Your code only specifies the intervals, but you have at least to specify the value to be returned for the last interval of the sequence. The fourth argument is the value returned by the function when the first interval is absent.
Additionally, you have to specify at least 3 parameters to "typeOfNext". Your code only specifies the intervals, but you have at least to specify the value to be returned for the last interval of the sequence. The fourth argument is the value returned by the function when the first interval is absent.
Thank you, rdumeur. It now works in postprocess script, but still doesn't work in main flow script.
The following code will report error: 未绑定的表达式：typeOfNext(p,A[1],0,0).
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; main
{ thisOplModel.generate(); cp.startNewSearch(); writeln(
"p " + thisOplModel.p);
for (var i=1; i<=10; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(thisOplModel.p,thisOplModel.A[i],0));
}
Thank you, rdumeur. It now works in postprocess script, but still doesn't work in main flow script.
The following code will report error: 未绑定的表达式：typeOfNext(p,A[1],0,0).
<pre class="jivepre">
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; main
{ thisOplModel.generate(); cp.startNewSearch(); writeln(
"p " + thisOplModel.p);
for (var i=1; i<=10; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(thisOplModel.p,thisOplModel.A[i],0));
}
</pre>
Thank you, rdumeur. It now works in postprocess script, but still doesn't work in main flow script.
The following code will report error: 未绑定的表达式：typeOfNext(p,A[1],0,0).
<pre class="jivepre">
using CP;
int n=10; dvar interval A[i in 1..10] size 2;
int T[i in 1..10] = i; dvar sequence p in A types T; subject to
{ noOverlap(p);
}; main
{ thisOplModel.generate(); cp.startNewSearch(); writeln(
"p " + thisOplModel.p);
for (var i=1; i<=10; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + Opl.typeOfNext(thisOplModel.p,thisOplModel.A[i],0));
}
</pre>
It seems that there is a dysfunction in the way tyeOfnext is used in this context.
As a workaround you could try this:
using CP;
int n=10; dvar interval A[i in 1..n] size 2;
int T[i in 1..n] = i; dvar sequence p in A types T; dvar
int x in 1..1; subject to
{ noOverlap(p);
};
int TN[i in 1..n] = typeOfNext(p, A[i],0); main
{ thisOplModel.generate(); cp.solve(); writeln(
"p " + thisOplModel.p);
for (var i=1; i<= thisOplModel.n; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + thisOplModel.TN[i]);
}
I hope this helps,
Chris.
Hello,
It seems that there is a dysfunction in the way tyeOfnext is used in this context.
As a workaround you could try this:
<pre class="jivepre">
using CP;
int n=10; dvar interval A[i in 1..n] size 2;
int T[i in 1..n] = i; dvar sequence p in A types T; dvar
int x in 1..1; subject to
{ noOverlap(p);
};
int TN[i in 1..n] = typeOfNext(p, A[i],0); main
{ thisOplModel.generate(); cp.solve(); writeln(
"p " + thisOplModel.p);
for (var i=1; i<= thisOplModel.n; i++) writeln(
"typeOfNext(p,A[" + i +
"],0) " + thisOplModel.TN[i]);
}
</pre>