Decision Optimization

Decision Optimization

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

 View Only
  • 1.  How it can be speed up ?

    Posted Mon May 12, 2008 05:44 PM

    Originally posted by: SystemAdmin


    [shadi said:]

    my .net program execution became very very slow, How it can be speed up ?
    my code is as follow:

    String applicationPath  = Application.StartupPath;
    OplFactory oplFCP = new OplFactory();
    OplErrorHandler errHandler = oplFCP.CreateOplErrorHandler(Console.Out);
    OplFactory.DebugMode=true;
    CP cp = oplFCP.CreateCP();
    OplModelSource modelSource=oplFCP.CreateOplModelSource(applicationPath + "\\OPLFiles\\btpair.mod");
    OplDataSource dataSource=oplFCP.CreateOplDataSource(applicationPath + "\\OPLFiles\\TelAviv.dat");
    OplSettings settings = oplFCP.CreateOplSettings(errHandler);
    OplModelDefinition def=oplFCP.CreateOplModelDefinition(modelSource,settings);
    OplModel oplCP=oplFCP.CreateOplModel(def,cp);
    OplDataElements CpDataElements= oplFCP.CreateOplDataElements();
    CpDataElements.AddElement(CpDataElements.MakeElement("coverTrip", 2));
    oplCP.AddDataSource(CpDataElements);
    oplCP.AddDataSource(dataSource);
    oplCP.Generate();



    int nbBusCategory  = GetSizeTuple(oplCP, "BusCategories");
    int nbTrips  = GetSizeTuple(oplCP, "Timetable");
    //MessageBox.Show(nbTrips.ToString());

    int nbLoops=nbBusCategory*nbTrips;


    ILOG.Concert.IIntMap MyDepTimeArray=getIlogArray(oplCP, "DepTime");
    ILOG.Concert.IIntMap MyArrTimeArray=getIlogArray(oplCP, "ArrTime");
    ILOG.Concert.IIntMap MyOriginArray=getIlogArray(oplCP, "Origin");
    ILOG.Concert.IIntMap MyDestinationArray=getIlogArray(oplCP, "Destination");
    ILOG.Concert.IIntMap MyStartFromDepotArray=getIlogArray(oplCP, "StartFromDepot");
    ILOG.Concert.IIntMap MyDistanceArray=getIlogArray(oplCP, "Distance");
    ILOG.Concert.IIntMap MyisEmptyTripArray=getIlogArray(oplCP, "isEmptyTrip");
    ILOG.Concert.IIntMap MytripTypeArray=getIlogArray(oplCP, "tripType");
    ILOG.Concert.ITupleSet MyTimeTable=oplCP.GetElement("Timetable").AsTupleSet();



    // MessageBox.Show(MyOriginArray.ToString());
    // MessageBox.Show(CpDataElements.GetElement("coverTrip").AsInt().ToString());
    // MessageBox.Show(oplCP.GetElement("coverTrip").AsInt().ToString());

    int LoopsCounter=1;
    int nSeq=oplCP.GetElement("nSeq").AsInt();
    //MessageBox.Show(nSeq.ToString());


    for (int BusCategoryCounter=0;BusCategoryCounter<nbBusCategory-1;BusCategoryCounter++)<br /> {
    string BusCategoryName=GetFieldByIndex(oplCP,BusCategoryCounter,"BusCategories", "busCategoryId");
    for (int Tripscounter=5;Tripscounter<nbTrips-1;Tripscounter++)<br /> {

    this.Text=LoopsCounter + " from " + nbLoops.ToString();

    OplFactory oplFCPWithoutPreporocess = new OplFactory();
    OplErrorHandler errHandlerWithoutPreprocess = oplFCPWithoutPreporocess.CreateOplErrorHandler(Console.Out);
    OplFactory.DebugMode=true;
    CP cpWithoutPreprocess = oplFCPWithoutPreporocess.CreateCP();
    OplModelSource modelSourceWithoutPreprocess=oplFCPWithoutPreporocess.CreateOplModelSource(applicationPath + "\\OPLFiles\\btpairWithoutPreprocess.mod");
    OplDataSource dataSource2=oplFCPWithoutPreporocess.CreateOplDataSource(applicationPath + "\\OPLFiles\\TelAvivWithoutProcess.dat");
    OplSettings settingsWithoutPreprocess = oplFCPWithoutPreporocess.CreateOplSettings(errHandlerWithoutPreprocess);
    OplModelDefinition defWithoutPreporoces=oplFCPWithoutPreporocess.CreateOplModelDefinition(modelSourceWithoutPreprocess,settingsWithoutPreprocess);
    OplModel oplCPWithoutPreprocess=oplFCPWithoutPreporocess.CreateOplModel(defWithoutPreporoces,cpWithoutPreprocess);
    OplDataElements CpDataElementsWithoutPreprocess= oplFCPWithoutPreporocess.CreateOplDataElements();
    CpDataElementsWithoutPreprocess.AddElement(CpDataElementsWithoutPreprocess.MakeElement("coverTrip", Tripscounter));

    //oplCPWithoutPreprocess.AddDataSource(CpDataElementsWithoutPreprocess);
    OplDataSource dataSource1 = new MyParamsCP(oplFCPWithoutPreporocess, Tripscounter,BusCategoryName,MyDepTimeArray,MyArrTimeArray,MyOriginArray,MyDestinationArray,MyStartFromDepotArray,MyDistanceArray,MyisEmptyTripArray,MytripTypeArray,MyTimeTable);
    oplCPWithoutPreprocess.AddDataSource(dataSource1);
    oplCPWithoutPreprocess.AddDataSource(dataSource2);



    oplCPWithoutPreprocess.Generate();
    oplCPWithoutPreprocess.CP.StartNewSearch();
    int count=0;
    while (oplCPWithoutPreprocess.CP.Next() )
    {
    ILOG.Concert.IIntMap MytripSeqArray=oplCPWithoutPreprocess.GetElement("tripSeq").AsIntMap();

    GC.Collect();

    int size=pairCst.Count;
    IIntVar MyPay=oplCPWithoutPreprocess.GetElement("pay").AsIntVar();

    double Cost=oplCPWithoutPreprocess.CP.GetValue(MyPay);
    pairCst_T newpairCst=new pairCst_T(size,Cost,BusCategoryCounter);
    pairCst.Add(newpairCst);

    for (int i=1;i<MytripSeqArray.Size;i++)<br /> {


    if (MyOriginArray.Get(MytripSeqArray.Get(i)) != MyDestinationArray.Get(MytripSeqArray.Get(i)))
    {
    int g=MytripSeqArray.Get(i);
    int j=0;
    pairIdx_T newpair=new pairIdx_T(g,j,size);
    pairIdx.Add(newpair);
    }
    //MessageBox.Show(oplCPWithoutPreprocess.GetElement("tripSeq").AsIntVarMap().Get(i).ToString());

    //if (MyOriginArray.Get(oplCPWithoutPreprocess.GetElement("tripSeq").AsIntVarMap().Get(i)))


    }


    count++;

    }
    LoopsCounter++;
    //MessageBox.Show(count.ToString());
    //ILOG.Concert.IIntMap MyOriginArray=getIlogArray(oplCPWithoutPreprocess, "Origin");
    //MessageBox.Show(oplCPWithoutPreprocess.GetElement("coverTrip").AsInt().ToString());
    //MessageBox.Show(oplCPWithoutPreprocess.GetElement("coverTrip").AsInt().ToString());
    //CpDataElements.AddElement(CpDataElements.MakeElement("coverTrip", counter));

    oplFCPWithoutPreporocess.End();

    }


    }
    oplFCP.End();


    [b]the two for loop generate about 81*3 loops [/b]


    Kshieboun Shadi


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: How it can be speed up ?

    Posted Tue May 13, 2008 02:41 AM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    do you have any hint about where the time is going ?
    Have you used any profile tool to know which methods is taking more time ?

    Alain
    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: How it can be speed up ?

    Posted Tue May 13, 2008 11:25 AM

    Originally posted by: SystemAdmin


    [shadi said:]

    Alain,
    the method that take time is the Next() method
    becuase when i limit
    while (oplCPWithoutPreprocess.CP.Next() && count<20)<br /> {
                                            ....................
                                            count++;
    }

    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: How it can be speed up ?

    Posted Tue May 13, 2008 11:27 AM

    Originally posted by: SystemAdmin


    [shadi said:]

    Alain,
    the method that take time is the Next() method
    becuase when i limit it using the following:
                while (oplCPWithoutPreprocess.CP.Next() && count<20)<br />              {
                                            ....................
                                            count++;
                  }

    i get very fast solution.



    #ConstraintProgramming-General
    #DecisionOptimization


  • 5.  Re: How it can be speed up ?

    Posted Tue May 13, 2008 01:00 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,

    then it would mean that the time is spent in CP Optimizer looking for the next solution.
    May be someone with more CP knowledge could help changing some formulation or adding some search phase to speed this search.

    Have you looked at how search phases work ?

    Alain
    #ConstraintProgramming-General
    #DecisionOptimization