Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem in writing my own constraint in a function

    Posted 03/31/16 12:36 AM

    Originally posted by: FiFila


    Hi;

    What is the application of "demon" in writing my own constraint as a function? I do not know how to write a global constraint?

    For instance:

    I want to solve the following question. 

    As it has been shown in the attachment you can see my small example (x[1..5]) are the inputs of layer1. Each layer is replaced with Tansig function (tansig(xij)->xij) and then  sum(x1i*w1ji)+b1=x2j (i,j=1..5 and x2j are inputs of layer 2) &&  sum(x2j*w2j)+b2=y (y is output), I want to minimize the "y" considering the constraints for instance: x[1]+2*x[2]*x[2]!=20;    x[3]+0.2x[4]!=2.1; and similar constraints .....  (These constraint can be written by model.add() but what is my problem is how to implement the NN section and how to achieve the minimization of neural network) {because I have at least 3 layers }.

    when I want to model.add(other constraints). I think that this is not possible to call a constraint several times in combination of other constraint (to be able to call this function several times base on needing). This is the reason I think I should call a function (IloConstraint:NN). Although I do not know how to write a function for iloconstraint.

    Best regards

    Fila


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: Problem in writing my own constraint in a function

    Posted 03/31/16 04:33 AM

    Originally posted by: ol


    Hello,

    a model is a system of constraints, and the solver aims at solving the constraint system. There is no such things as "calling a constraint" when you stay at the model and solve approach.

    If you have a specific problem, and need to "enter inside" the solving mechanism itself, then demons, and custom constraints may be useful.

    Do you have a specific problem? can you clarify your question?

     

    Regars,

    Olivier

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: Problem in writing my own constraint in a function

    Posted 03/31/16 10:20 AM

    Originally posted by: FiFila


    Hi Olivier;

     

    Thank you very much for your reply. Yes, as I have written, I want to write my own solving mechanism inside. I had thought that for writing a section of constraints by myself I should write it as a function to call it? This is not true?

    I have read the CP optimizer extension manual but I did not understand how to write demon, and custom constraints? (Propagate,demon,post). I did not understand how to use demon in combination of propagate and post.

    About my question, I am checking the ability of solving a problem that I have written above as a simple model.

     

    Best regards

    Fila


    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: Problem in writing my own constraint in a function

    Posted 04/01/16 05:20 AM

    Originally posted by: ol


    Hello,

    first of all, if you want to use a constraint solver, you need to express your problem with variables, constraints and objective functions, i.e. a constraint model.

    Then, you have to decide how to write this model in the language of a given solver.

    It seems to me that you want to do the 2nd step (or even a third step) before the first one, which, in your case, is easy to do. So do the first step first (e.g. decide if you want sigmoid or Heavyside, etc.), and you will see that everything will be clear.

    Regards,

    Olivier


    #ConstraintProgramming-General
    #DecisionOptimization


  • 5.  Re: Problem in writing my own constraint in a function

    Posted 04/02/16 12:02 PM

    Originally posted by: FiFila


    Hi Olivier;

    Thanks for your reply but I did not understand why you said I go to the next steps. Let me explain again, I need the Sigmoid and the formula that I have written. Each input multiplies to sigmoid functions in addition to other needing such as reach the goals of constraints. 

     

    Regards

    Fila


    #ConstraintProgramming-General
    #DecisionOptimization


  • 6.  Re: Problem in writing my own constraint in a function

    Posted 04/04/16 11:32 AM

    Originally posted by: ol


    Hello,

    ok, if you have a *clean* mathematical model, you have the first step.

    You can send it if you want and ask a question on this clean model, this will make easier for people to help you.

    If the problem you have is the activation of the neuron, note that you can implement a Heavyside function by simple constraints, like:

    (expression > 0) <= (H ==1)

    (expression < 0) <= (H ==0)

    When the expression is greater than 0,  (expression > 0) becomes true, worth 1. Then we have  that 1 <= (H ==1) forces H to be 1.

    You see? no need to implement your own specific constraint.

    About sigmoid: you can also implement a sigmoid, but I do not think this is interesting, it is used to smooth the transition, but CP does not need smothness, and the Heavyside function will do at least as well.

    Regards,

    Olivier


    #ConstraintProgramming-General
    #DecisionOptimization


  • 7.  Re: Problem in writing my own constraint in a function

    Posted 04/04/16 02:06 PM

    Originally posted by: FiFila


    Hi Olivier;

    Thanks for your reply but I think I did not express correctly what are my problems.

    My problems are in two sides.

    First and my main problem is related to Tansig. I have to work with Tansig. The inputs of each layer (x[i][j] i:layer, i:index of )are changed by applying Tansig function and then they are multiple with (wi) and add with (bi) [ sum(tansig(x[i][j])*w[i][j])for (j in range x[i])+bi]. The problem that I encounter with Tansig is that iits amount changes very few by changing the inputs. As the CP works with integer amounts, I should multiple it with a power of ten but my interval expands exponentially. Therefore, the time will be so much high. I do not know how to reduce the searching space.

    Second problem is related to my knowledge in CP because I am beginner in this field.

    I want to minimize the y by considering the following inputs.

    The numbers of my inputs and my constraints are very high. And the number of layer is more than this. For instance a very small example with 5 inputs and two input layers. 

     

    Model:

    xrange 1..5 

    for j in xrange  x[1][j]=Tansig[1][j];

    x[2][1]=x[1][1]*w[1][1][1]+x[1][2]*w[1][2] [1]+x[1][3]*w[1][3][1] +x[1][4]*w[1][4] [1]+b[1][1];

    x[2][2]=x[1][1]*w[1][1][2]+x[1][2]*w[1][2] [2]+x[1][3]*w[1][3][2] +x[1][4]*w[1][4] [2]+b[1][2];

    x[2][3]=x[1][1]*w[1][1][3]+x[1][2]*w[1][2] [3]+x[1][3]*w[1][3][3] +x[1][4]*w[1][4] [3]+b[1][3];

    x[2][4]=x[1][1]*w[1][1][4]+x[1][2]*w[1][2] [4]+x[1][3]*w[1][3][4] +x[1][4]*w[1][4] [4]+b[1][4];

    x[2][5]=x[1][1]*w[1][1][5]+x[1][2]*w[1][2] [5]+x[1][3]*w[1][3][5] +x[1][4]*w[1][4] [5]+b[1][5];

    for j in xrange x[2][j]=Tansig[2][j];

    y=x[2][1]*w[2][1][1]+x[2][2]*w[2][2] [1]+x[2][3]*w[2][3][1] +x[2][4]*w[2][4] [1]+b[2][1];

     

    Goal:

    Min y

    Subject to:

    x[1][1]+2*x[1][2]*x[1][2]!=20;    x[1][3]+0.2x[1][4]!=2.1x[1][3]+x[1][2]=4;...

     

    Regards

    Fila

     

     

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 8.  Re: Problem in writing my own constraint in a function

    Posted 04/04/16 04:59 PM

    Originally posted by: ol


    for the sigmoid, you can do:

    void sigmoid() {
      IloEnv env;
      IloModel m(env);
      IloIntVar n(env, -10,10);
      IloIntVar A(env, 0,1);
      IloExpr x = n *0.01;
      IloExpr tansig = 2/(1+IloExponent(-2*x))-1;
      m.add((tansig >= 0.0001) <= (A==1));
      m.add((tansig <= -0.0001) <= (A==0));
      IloCP cp(m);
      cp.setParameter(IloCP::Workers,1);
      cp.startNewSearch();
      while (cp.next()) {
        cout<<cp.getValue(n)<<":"<<cp.getValue(A)<<":"<<cp.getValue(tansig)<<endl;
      }
      env.end();
    }

    In your case x will be the weighted sum, and A will be the final state of the neuron.

    Note the 0.0001 threshold.

    for minimizing an expression y, in C++ you can do:
      

      m.add(IloMinimize(env, y));

     

    Regards,

    Olivier

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 9.  Re: Problem in writing my own constraint in a function

    Posted 04/04/16 06:40 PM

    Originally posted by: FiFila


    Hi Olivier;

    Thanks for your reply but I do not understand the reason of adding the some lines of your code:

     

    For instance:n is number of input and x is input? Why you write this line?   IloExpr x = n *0.01; Why you multiple with 0.01?

    What is your meaning of applying this line:   cp.setParameter(IloCP::Workers,1); ? 

    I also do not know why you add this line: m.add((tansig >= 0.0001) <= (A==1));

     

    Also,I do not know is it possible to define a 3D arrays in CPO?How?

     

    Best regards

    Fila


    #ConstraintProgramming-General
    #DecisionOptimization


  • 10.  Re: Problem in writing my own constraint in a function

    Posted 04/05/16 09:07 AM

    Originally posted by: ol


    Hello,

    the answers to your questions:

     

    - n and x:

    in your problem you have float linear expressions from integer vars, so I took n, an integer var, and multiplied it by 0.01, hoping that it may help you to see an example close to your problem.

     

    - cp.setParameter(IloCP::Workers,1);

    means only one solving thread. Remove it, run and see that the display will not be so easy to read (if you computer is multi cores).

     

    - m.add((tansig >= 0.0001) <= (A==1));

    that was explained in my answer above on a way to implement an heavyside function. I re-insist that you can simply use the Heavyside alone, no need for tansig.  In this case replace with:

    m.add((x>= 0.0001) <= (A==1));

     

    - 3D arrays:

    I do not not know what you know. Maybe it will help you to first learn the basics of C++, independently of CPO I mean.  An array can be an array of pointers pointing to arrays.

     

    Regards,

    Olivier

     

     


    #ConstraintProgramming-General
    #DecisionOptimization