Hello,
I am trying to calculate the arc cosine of values but
I think i cannot do it directly. please help me with a way to do it.
Thank you.
Topic

Re: Calculating arc Cosine
20121122T18:06:13ZThis is the accepted answer. This is the accepted answer.Hello,
do you mean computing the arc cosine of an IloNumExpr?
In the general case, you need to define your own constraint in the C++ API, at the Ilc level and then wrap it to the Ilo level with the macro ILOCPCONSTRAINTWRAPPER.
Depending on your need, you may be able to simply use the relation cosinus(a)=adjacent / hypotenuse. If you have integers variables, you may also be able to use element constraint for example with tabulated values. Can you give some precisions on your exact need?
Regards,
Olivier 
Re: Calculating arc Cosine
20121123T07:12:06ZThis is the accepted answer. This is the accepted answer. ol
 20121122T18:06:13Z
Hello,
do you mean computing the arc cosine of an IloNumExpr?
In the general case, you need to define your own constraint in the C++ API, at the Ilc level and then wrap it to the Ilo level with the macro ILOCPCONSTRAINTWRAPPER.
Depending on your need, you may be able to simply use the relation cosinus(a)=adjacent / hypotenuse. If you have integers variables, you may also be able to use element constraint for example with tabulated values. Can you give some precisions on your exact need?
Regards,
Olivier
Thank you for your response.
As for your suggested method, I am not familiar with using C++ API. Could you please explain further.
The problem that I am trying to calculate the angle (decision variable) between two vectors during the optimization run. While it is not possible to use trigonometric functions, the question is whether there is another way to calculate the angle. Using tabulated values seems difficult, since the angle is derived from calculating the arcosine of the vectors dotproduct and they are floating numbers.
Is there a way to calculate the angle similar to how the mathematical function is calculated by software.
Best Wishes 
Re: Calculating arc Cosine
20121123T11:03:50ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20121123T07:12:06Z
Dear Olivier,
Thank you for your response.
As for your suggested method, I am not familiar with using C++ API. Could you please explain further.
The problem that I am trying to calculate the angle (decision variable) between two vectors during the optimization run. While it is not possible to use trigonometric functions, the question is whether there is another way to calculate the angle. Using tabulated values seems difficult, since the angle is derived from calculating the arcosine of the vectors dotproduct and they are floating numbers.
Is there a way to calculate the angle similar to how the mathematical function is calculated by software.
Best Wishes
here is an example of what you could do if you use the C++ API; you may want to improve it a little bit, for example, the floating point errors when computing a cosine is rougly bounded with the addition of epr,+eps, and for simplifying I forced the angle to be between 0 and pi, but that is the idea.
If you are using OPL or java API, you may simply use a taylor serie for the arc cosine (or several taylor series, one around 0, one around 0.2,... with ifThen expressions if you want a better precision).
Regrds,
Olivier
#include <ilcp/cpext.h> #include <ilcp/ilosolver.h> #include <math.h> ILOSTLBEGIN #define PI 3.14159265358979323846 class MyIlcArccosI : public IlcConstraintI { private: IlcFloatVar _x; IlcFloatVar _y; public: MyIlcArccosI(IloCP s, IlcFloatVar x, IlcFloatVar y); void post(); void propagate(); }; MyIlcArccosI::MyIlcArccosI(IloCP s, IlcFloatVar x, IlcFloatVar y): IlcConstraintI(s), _x(x), _y(y) { } void MyIlcArccosI::post() { _x.whenRange( this); _y.whenRange( this); } void MyIlcArccosI::propagate() { _x.setRange(0,PI); _y.setRange(1,1); IlcFloat eps=0.0000001; _x.setRange(acos(_y.getMax())eps, acos(_y.getMin())+eps); _y.setRange(cos(_x.getMax())eps,cos(_x.getMin())+eps); } IlcConstraint MyIlcArccos(IloCP cp, IlcFloatVar x, IlcFloatVar y) { return new (cp.getHeap()) MyIlcArccosI(cp, x, y); } //x == arccos(y) ILOCPCONSTRAINTWRAPPER2(MyIloArccos, cp, IloNumVar, x, IloNumVar, y) { use(cp, x); use(cp, y); return MyIlcArccos(cp, cp.getFloatVar(x), cp.getFloatVar(y)); } void Model(IloEnv env) { IloNumVar x(env, 33, 44); IloNumVar y(env, 100, 23.44); IloModel mdl(env); mdl.add(IloMaximize(env, x)); mdl.add(x); mdl.add(y); IloExtractable ct1 = MyIloArccos(env,x,y); mdl.add(ct1); IloCP cp(mdl); cp.solve(); cout << "Arccos : " << cp.domain(x) << " " << cp.domain(y) << endl; cp.end(); } int main( int argc, const char * argv[]) { IloEnv env; try { Model(env); } catch (IloException & ex) { env.out() << "Caught: " << ex << endl; } env.end(); return 0; }

Re: Calculating arc Cosine
20121123T13:30:03ZThis is the accepted answer. This is the accepted answer. ol
 20121122T18:06:13Z
Hello,
do you mean computing the arc cosine of an IloNumExpr?
In the general case, you need to define your own constraint in the C++ API, at the Ilc level and then wrap it to the Ilo level with the macro ILOCPCONSTRAINTWRAPPER.
Depending on your need, you may be able to simply use the relation cosinus(a)=adjacent / hypotenuse. If you have integers variables, you may also be able to use element constraint for example with tabulated values. Can you give some precisions on your exact need?
Regards,
Olivier
since I am using OPL, I will try Taylor series.