Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  still trying to integrate trigonometric functions into variable expression

    Posted 03/22/12 04:04 AM

    Originally posted by: Jutto


    Hello

    I am still having problems solving the integration of a trigonometric function in a variable expression.
    This is what I am trying: Since mathematical functions do not work for variable expressions, I am trying to pre-calculate sine and cosine functions of all 360 angle degrees in a execution block and then call their results, based on the dvar angle, in a dexpr definition for line length calculation.

    For the last two dexpr (linex and liney), the software indicates the following mistake: Cannot use type floatrange for userFunction.

    How can I get around this?
    This is some part of the current code:

    
    using CP; ... 
    
    int numPoints = 5; 
    
    int nP = numPoints; 
    
    int boundx = 10; 
    
    int boundy = 8; 
    
    int dia = 12;   
    
    float Sine[0..359]; 
    
    float Cosine[0..359];   range Points         = 1..nP;   dvar 
    
    int x0 in 0..boundx; dvar 
    
    int y0 in 0..boundy; dvar 
    
    int line[Points]    in 0..dia; dvar 
    
    int alpha[Points]  in 0..359;   ... dexpr 
    
    float Perimeter                = (sum (p in Points)(abs(line[p])));   dexpr 
    
    float linex[p in Points]     = (line[p]*Cosine(alpha)); dexpr 
    
    float liney[p in Points]      = (line[p]*Sine(alpha));   execute CalcCoSine 
    { 
    
    for (var d=0;d<360;d++) 
    { Sine[d]   = Math.sin (d*Math.PI/180) Cosine[d] = Math.cos (d*Math.PI/180) writeln (Sine[d],Cosine[d]) 
    } 
    };
    


    Thanks.
    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: still trying to integrate trigonometric functions into variable expression

    Posted 03/22/12 06:00 AM

    Originally posted by: ol


    Hello,

    there were two problems in your code: missing parameter and "()" instead ot "[]":
    using CP;

    int numPoints = 5;
    int nP = numPoints;
    int boundx = 10;
    int boundy = 8;
    int dia = 12;

    float Sinehttp://0..359;
    float Cosinehttp://0..359;

    range Points = 1..nP;

    dvar int x0 in 0..boundx;
    dvar int y0 in 0..boundy;
    dvar int linePoints in 0..dia;
    dvar int alphaPoints in 0..359;

    dexpr float Perimeter = (sum (p in Points)(abs(line[p])));

    dexpr float linexp in Points = (line[p]*Cosine[alphap]);
    dexpr float lineyp in Points = (line[p]*Sine[alphap]);

    execute CalcCoSine {
    for (var d=0;d<360;d++) {
    Sine[d] = Math.sin (d*Math.PI/180)
    Cosine[d] = Math.cos (d*Math.PI/180)
    writeln (Sine[d],Cosine[d])
    }
    };
    Regards,
    Olivier
    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: still trying to integrate trigonometric functions into variable expression

    Posted 03/22/12 06:31 AM

    Originally posted by: ol


    sorry, the forum doesn't like the [].
    Should be more readable:

    dexpr float linex[p in Points] = (line[p]*Cosine[alpha[p]]);
    dexpr float liney[p in Points] = (line[p]*Sine[alpha[p]]);

    Olivier
    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: still trying to integrate trigonometric functions into variable expression

    Posted 03/23/12 04:33 AM

    Originally posted by: Jutto


    Thanks a lot, Olivier.
    #ConstraintProgramming-General
    #DecisionOptimization