Decision Optimization

 View Only
  • 1.  State variables in CP

    Posted Fri December 13, 2024 02:00 AM

    I have a tank into which I put a liquid (eg chocolate) and at a later time I extract this liquid
    I am using a state variable "Flavour" (= chocolate) to represent the state of the tank, and using always_in constraint for the input and output tasks. That works fine, EXCEPT, since there is a time delay between the input and output tasks, the tank reverts to 'no state' in the interim

    How can I enforce the tank state to be = chocolate from the beginning of the input task until the end of the output task?

     

    Any suggestions would be appreciated

     

    Ross Dye

    0400669880

     



  • 2.  RE: State variables in CP

    Posted Fri December 13, 2024 10:53 AM

     using CP;
     
     dvar interval input size 2;
     dvar interval output size 2;
     
     stateFunction s;
     
     subject to
     {
       alwaysEqual(s,input,1);
       alwaysEqual(s,output,1);
     
       startOf(input)==1;
       startOf(output)==8;
     }
    
    execute
    { 
    
      writeln(s);
     
    } 

    gives

    stepwise{ -1 -> 1; 1 -> 3; -1 -> 8; 1 -> 10; -1 }

    But you can use a new interval which contains both intervals and then you do not get the -1 state in the middle

    using CP;
     
     dvar interval input size 2;
     dvar interval output size 2;
     
     dvar interval inputoutput;
     
     stateFunction s;
     
     subject to
     {
       alwaysEqual(s,inputoutput,1);
       startAtStart(inputoutput,input);
       endAtEnd(inputoutput,output);
       
       
     
       startOf(input)==1;
       startOf(output)==8;
     }
    
    execute
    { 
    
      writeln(s);
     
    } 
     

    which gives

    stepwise{ -1 -> 1; 1 -> 10; -1 }



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: State variables in CP

    Posted Fri December 13, 2024 07:50 PM

    Thanks Alex

    I am using docplex cp with python, so the code provided is unfamiliar (but understandable)

    I'm not sure how the first example works, but I can definitely understand the second.

    As I understand it, you propose that an additional interval_var is created that spans the input and output intervals. Using this to control the state variable would definitely work.

    However, how do I go about dynamically creating this additional interval_var at runtime? I do not know in advance how many may be needed.

    Perhaps a technique of creating a 'pool' of optional interval_vars then using them as required.

    Is this possible?

    Can anyone suggest a technique?

     

    Thanks

     

    Ross Dye

    0400669880

     






  • 4.  RE: State variables in CP

    Posted Mon December 16, 2024 01:43 AM

    Tanks for your advice Alex

    I used your second suggestion with new 'spanning' activity

    Works well

    Thanks again

    Ross



    ------------------------------
    Ross Dye
    ------------------------------