Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

how to compute some variables before minimize(maximize)

  • 1.  how to compute some variables before minimize(maximize)

    Posted Thu June 19, 2008 11:41 AM

    Originally posted by: SystemAdmin


    [freedomfly said:]

    I want to compute some some variables such as cov[i][j] ,r[i] before minimizing, how to do it? thanks!

    the code is the following(it does not work).

    int T=...;
    int N=...;
    int K=...;
    float l=...;
    float u=...;
    float a=...;
    float c=...;
    //float b=...;
    range t=1..T;
    range i=1..N;
    range j=1..N;
    float z[i]=...;
    float weight0[i];
    float stockreturn[t][i]=...;
    //float indexreturn[t]=...;
    dvar float+ weight[i];
    dvar float+ weight1[i];
    dvar float+ weight2[i];
    dvar boolean  y[1..N];
    dexpr float r[i]=sum(t in 1..T)stockreturn[t][i]/T;
    dexpr float cov[i][j]=(1/T)*sum(t in 1..T)(stockreturn[t][i]-r[i])*(stockreturn[t][j]-r[j]);
         
    minimize
      sum(i,j in 1..N )
          cov[i][j]*(weight[i]-weight0[i])*(weight[j]-weight0[j]);
       
       
    subject to {
           
          sum( i in 1..N )
              //weight[i]==1.0;
            (weight[i]+a*weight1[i]+a*weight2[i])==1.0;
          sum(i in 1..N)
                y[i]<=K;<br />        forall(i in 1..N)
                l*y[i]-weight[i]<=0;<br />        forall(i in 1..N)
               weight[i]-u*y[i]<=0;<br />        sum(i in 1..N )
            (a*weight1[i]+a*weight2[i]-c)<=0;<br />        forall(i in 1..N)
              weight[i]-weight1[i]+weight2[i]-z[i]==0;
           
                 
    }
    execute DISPLAY {
    for (var s=1; s<=N; s++)<br /> {writeln("weight[s] = ",weight[s])}

    }         


    freedomfly
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: how to compute some variables before minimize(maximize)

    Posted Thu June 19, 2008 01:27 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    HI,

    seems like cov is not a expression on "decision variables" (i.e. variables passed to the engine on which decisions are taken).
    It is simply a calculated array of data.
    You should try with :
    float cov[j]=(1/T)*sum(t in 1..T)(stockreturn[t]-r)*(stockreturn[t][j]-r[j]);

    the initialization should say on which index j is to be used, like :
    float cov[j in XXXX]=(1/T)*sum(t in 1..T)(stockreturn[t]-r)*(stockreturn[t][j]-r[j]);

    Same thing for r.

    Hope this helps,

    Alain
    #DecisionOptimization
    #OPLusingCPOptimizer