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