Topic
  • 8 replies
  • Latest Post - ‏2012-10-27T02:07:49Z by qtbgo
qtbgo
qtbgo
134 Posts

Pinned topic how to access the types of inerval variables in flow control or postprocess

‏2012-10-25T06:20:14Z |
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;
Updated on 2012-10-27T02:07:49Z at 2012-10-27T02:07:49Z by qtbgo
  • qtbgo
    qtbgo
    134 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T06:27:53Z  
    sorry, opl.n+1 should be oplmodel.n+1
  • rdumeur
    rdumeur
    73 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T11:45:29Z  
    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,

    Cheers,
  • qtbgo
    qtbgo
    134 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T12:29:13Z  
    • rdumeur
    • ‏2012-10-25T11:45:29Z
    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,

    Cheers,
    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?

    
    exectute 
    { writeln(
    "typeof vbtasks[1][1] ", typeOfNext(thisOplModel.bs[1] ,thisOplModel.vbtasks[1][1]) );  
    }
    
    doesn't work.
  • rdumeur
    rdumeur
    73 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T12:48:08Z  
    • qtbgo
    • ‏2012-10-25T12:29:13Z
    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?

    <pre class="jive-pre"> exectute { writeln( "typeof vbtasks[1][1] ", typeOfNext(thisOplModel.bs[1] ,thisOplModel.vbtasks[1][1]) ); } </pre> doesn't work.
    Dear qtbgo

    The following example works fine:
    
    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
  • rdumeur
    rdumeur
    73 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T12:51:47Z  
    • rdumeur
    • ‏2012-10-25T12:48:08Z
    Dear qtbgo

    The following example works fine:
    <pre class="jive-pre"> 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.

    Renaud
    Dear qtbgo,

    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.

    Cheers,
  • qtbgo
    qtbgo
    134 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-25T23:55:23Z  
    • rdumeur
    • ‏2012-10-25T12:51:47Z
    Dear qtbgo,

    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.

    Cheers,
    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)); 
    }
    
  • ChrisBr
    ChrisBr
    48 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-26T15:08:25Z  
    • qtbgo
    • ‏2012-10-25T23:55:23Z
    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="jive-pre"> 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>
    Hello,

    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.
  • qtbgo
    qtbgo
    134 Posts

    Re: how to access the types of inerval variables in flow control or postprocess

    ‏2012-10-27T02:07:49Z  
    Thank you very much.