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 float
range 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