private bool GetSolution(int n, ref uint WrapSol, ref List <uint>[] WrapSolClu) { bool ret = false; WrapSol = 0; WrapSolClu = null; if (!isloaded) { return(false); } pm.SetSolutions((uint)n); ret = pm.ComputeSolutions(parsol, parclu); //tolto il parallelo... //ret = pm.ComputeSolutions(false, false); if (ret) { WrapSol = pm.WrapperSolution; WrapSolClu = pm.WrapperSolutionClusters; } return(ret); }
static void EsempioMinimale() { String FileName = "Nome e Percorso del problema da elaborare"; PMed3 pmed; int m = 0; //per capacitated problem try { //Punto 1 pmed = new PMed3(Console.Write, 1); //Punto 2 if (pmed.Load(FileName, ref m)) { if (m == -1) //allora è di tipo uncapacitated (già caricato) { //.... //si può non fare niente oppure gestire cio che si deve gestire. // } else { //questo fase è necessaria perchè sono molto diversi i file come strutturazione. //invece che fare 2 metodi load, si è scelto di farne uno che a seconda di cosa ritorna //nel parametro reference m, fa capire di che tipo è il problema, //la seconda volta solo per i capacitated è da richiamare perchè la prima restituisce //quanti sono i problemi in esso contenuti, la seconda carica il problema scelto. int m_problem = 1; // dev'essere fra 1 e m. if (!pmed.Load(FileName, ref m_problem, false)) { Console.WriteLine("Impossibile caricare il file..."); return; } } //Fine Punto 2 //a questo punto ho il file caricato sia uncapacitated che capacitated //Punto 3 if (pmed.ComputeSolutions(true, true)) { //Punto 4 //gestione dati.... } else { Console.WriteLine("Erorre nella computazione..."); } } } catch (DllNotFoundException e) { Console.WriteLine("DLL NON TROVATA!!! \r\n{0}", e.Message); } }
private static void TestWrapper() { //Funzione per testare e capire il wrapper... Console.WriteLine("TEST wrapper: funzionamento e verifica del suo funzionamento."); PMed3 pmed3; try { pmed3 = new PMed3(Console.Write, 2, "TestWrap", true, false); } catch (Exception e) { Console.WriteLine("exception: {0}", e.Message); Console.WriteLine("{0}", Directory.GetCurrentDirectory()); return; } #if DEBUG //if (!pmed3.LoadTest(@"\\polocesena\polocesena\UtentiScienze\STUDENTI\raffaello.bertini\Desktop\AAA\Problems\pmedtest_verysmall.txt")) if (!pmed3.LoadTest(@"..\..\..\pmedtest_verysmall.txt")) { Console.WriteLine("ERROR LOAD FILE!!!"); return; } pmed3.ComputeSolutions(false, false); //pmed3.InitProblem(); #endif //if (!pmed3.Load(@"C:\Users\Raffaello\Documents\Uni\AAA\Proj_Exam\Problems\pmed1.txt")) //{ // Console.WriteLine("ERROR LOAD FILE!!!"); // return; //} //pmed3.ComputeSolutions(true, false); //if (!pmed3.InitProblem()) //{ // Console.WriteLine("init failed!! stop!"); // return; //} //pmed3.ShowTableau(); // DA FARE TESTARE UN SEMPLICE PROBLEMA pmed3 per il wrapper ed il formato // della matrice. // quindi fare un progetto che usa il wrapper e risolve il sistema lineare. }
private static void TestPMedWrapper_Large() { //risolviamo il Pmed1.txt in large!!! 10.000 PMed3 pmed3; uint nsol = 2; try { pmed3 = new PMed3(Console.Write, nsol, "TestWrap", false, false); } catch (Exception e) { Console.WriteLine("exception: {0}", e.Message); Console.WriteLine("{0}", Directory.GetCurrentDirectory()); return; } //#if DEBUG int m = 0; if (!pmed3.Load(@"..\..\..\pmed1.txt", ref m)) { Console.WriteLine("ERROR LOAD FILE!!!"); return; } pmed3.ComputeSolutions(false, false); //pmed3.InitProblem(); //#endif //pmed3.InitProblem(); //pmed3.BuildSolutionFromWrapper(); Console.ReadKey(); pmed3.ShowWrapperSolution(Console.Write); pmed3.CheckWrapperClusterSolution(); }
private static void TestWrapperUncapacitated() { PMed3 pmed3; uint nsol = 1; int m = 0; try { pmed3 = new PMed3(Console.Write, nsol, "TestWrap", false, false); } catch (Exception e) { Console.WriteLine("exception: {0}", e.Message); Console.WriteLine("{0}", Directory.GetCurrentDirectory()); return; } if (!pmed3.Load(@"..\..\..\pmed4.txt", ref m, false)) { Console.WriteLine("ERROR LOAD FILE!!!"); return; } pmed3.ComputeSolutions(false, false); //pmed3.InitProblem(); //#endif //pmed3.InitProblem(); //pmed3.BuildSolutionFromWrapper(); //Console.ReadKey(); //pmed3.ShowWrapperSolution(Console.Write); pmed3.CheckWrapperClusterSolution(); }
private static void TestPMedWrapper3CCS() { //Problema da testare : //ora proviamo con costo cluster... //Sol0 = {4,2} ; {1,0,3} //Sol1 = {3,1} ; {4,2,0} //C(Sol0) = {0,16}=16 ; {0,15,40}=55 = 71 //C(Sol1) = {0,40}=40 ; {0,16,24}=40 = 80 //min z = 16*S0c0 + 55*S0c1+ 40*s1c0 + 40*s1c1 //s.t. // s0c0 s0c1 s1c0 s1c1 //z 16 55 40 40 //0 0 1 0 1 //1 0 1 1 0 //2 1 0 0 1 //3 0 1 1 0 //4 1 0 0 1 PMed3 pmed3; uint nsol = 2; try { pmed3 = new PMed3(Console.Write, nsol, "TestWrap", true, false); } catch (Exception e) { Console.WriteLine("exception: {0}", e.Message); Console.WriteLine("{0}", Directory.GetCurrentDirectory()); return; } #if DEBUG //if (!pmed3.LoadTest(@"\\polocesena\polocesena\UtentiScienze\STUDENTI\raffaello.bertini\Desktop\AAA\Problems\pmedtest_verysmall.txt")) if (!pmed3.LoadTest(@"..\..\..\pmedtest_verysmall.txt")) { Console.WriteLine("ERROR LOAD FILE!!!"); return; } pmed3.ComputeSolutions(false, false); //pmed3.InitProblem(); #endif //ora modifico le soluzioni a piacimento... pmed3.SolutionsClusters[0][0].Clear(); pmed3.SolutionsClusters[0][0].Add(4); pmed3.SolutionsClusters[0][0].Add(2); pmed3.SolutionsClusters[0][1].Clear(); pmed3.SolutionsClusters[0][1].Add(1); pmed3.SolutionsClusters[0][1].Add(0); pmed3.SolutionsClusters[0][1].Add(3); pmed3.SolutionsClusters[1][0].Clear(); pmed3.SolutionsClusters[1][0].Add(3); pmed3.SolutionsClusters[1][0].Add(1); pmed3.SolutionsClusters[1][1].Clear(); pmed3.SolutionsClusters[1][1].Add(4); pmed3.SolutionsClusters[1][1].Add(2); pmed3.SolutionsClusters[1][1].Add(0); //da rendere publici per testare... //pmed3.InitProblem(); //pmed3.BuildSolutionFromWrapper(); pmed3.ShowWrapperSolution(Console.Write); //double obj = w.getObjectValue(prob); //double[] solvars = new double[4]; //Vettore deputato a contenere i valori della soluzione //w.getSolutionValues(prob, solvars, null, null, null); //for (int i = 0; i < solvars.Length; i++) // Console.WriteLine("{0} solvar {1}", solvars[i], i); //Console.WriteLine("VALORE OTTIMO TROVATO : {0} ", obj); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { backgroundWorkerParameter param = e.Argument as backgroundWorkerParameter; if (pm is PMed3) { if (!pm.ComputeSolutions(param.Parallel, param.Clusters)) { MessageBox.Show("An Error as occured, check Console Text Box for info.\r\n Maybe out of memory exception.", "PMedLib.dll error"); //MessageBox.Show("It's Better Close program and restart it!!!", "Warning !!!", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // else //tutto ok... // { // } } else { pm.ComputeSolutions(param.Parallel, param.Clusters); } //metto qui l'aggiornamenti della form e vari... ConsoleAppendText("\r\nFinished Computing Solutions..."); ConsoleAppendText(String.Format("\r\n--- Best Solution is {0} = {1}", pm.BestSolutionIndex, pm.Solutions[pm.BestSolutionIndex])); if (pm.WrapperSolution > 0) { ConsoleAppendText(String.Format("\r\n--- Wrapper Solution is = {0}", pm.WrapperSolution)); } pm.ShowElapsedTime(); ConsoleAppendText(String.Format("\r\nPopulating solution viewer...")); Stopwatch solw = new Stopwatch(); solw.Start(); //aggiorno la lista delle soluzioni alla fine... così da rendere l'algortimo più efficente... try { for (uint i = 0; i < pm.Nsolution; i++) { if (SolutionViewer.InvokeRequired) { SolutionViewer.Invoke(UpdateSolutionVieverCallBack, i); } else { UpdateSolutionViever(i); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "PMedian Project - Solution Viewer"); //cancello la lista altrimenti può crashare tutto!!! //e metto solo il meglio trovato... if (SolutionViewer.InvokeRequired) { SolutionViewer.Invoke(SolutionViewerClearCallBack); SolutionViewer.Invoke(UpdateSolutionVieverCallBack, pm.BestSolutionIndex); } else { SolutionViewer.Nodes.Clear(); UpdateSolutionViever(pm.BestSolutionIndex); } } solw.Stop(); ConsoleAppendText(String.Format("\r\nTime Elapsed Pouplation Solution Viewer {0}", solw.Elapsed)); }
private static bool ComputeBestof3Sol(string nomep) { //int i_sol = 3; int i_sol = 1; int i, j; TimeSpan timeelapsed = new TimeSpan(); //uint[] setN = {1000, 3000, 5000}; uint[] setN = { 1000 }; //uint[] setN = { 100, 500, 1000, 3000, 5000, 10000, 15000, 20000 }; uint setpofsol; //double MaxIterSec = 60 * 5; // 5 min; double MaxIterSec = 0.0; pmed.Seed = 1657; pmed.MaxIterSecond = MaxIterSec; swBatchOut.WriteLine("\r\nSeed = {0}", pmed.Seed); uint bestsol = int.MaxValue; bool isbestwrap = false; for (j = 0; j < setN.Length; j++) { Console.WriteLine("preparing computation {0} ...", setN[j]); pmed.SetSolutions(setN[j]); setpofsol = 0; //swBatchOut.WriteLine("Computing with {0} sols", setN[j]); bestsol = int.MaxValue; isbestwrap = false; timeelapsed = new TimeSpan(); for (i = 0; i < i_sol; i++) { Console.WriteLine("Computing SOl.."); if (!pmed.ComputeSolutions(true, true)) { swBatchOut.WriteLine("Cannot Compute Wrapper Solution!!! error!!!"); } /*else*/ if (bestsol > pmed.WrapperSolution) { if (pmed.WrapperSolution > 0) { if (pmed.WrapperSolution < pmed.Solutions[pmed.BestSolutionIndex]) { isbestwrap = true; } else { isbestwrap = false; } bestsol = pmed.WrapperSolution; //Console.WriteLine("\r\nChecking Solutions Set of p ..."); //setpofsol = pmed.CheckPofSolutions(false); timeelapsed = pmed.GetTotalElapsedTime(); } else { swBatchOut.WriteLine("{0} : No Wrapper Computed!!!!", nomep); if (bestsol > pmed.Solutions[pmed.BestSolutionIndex]) { Console.WriteLine("\r\nChecking Solutions Set of p ..."); //setpofsol = pmed.CheckPofSolutions(false); timeelapsed = pmed.GetTotalElapsedTime(); bestsol = pmed.Solutions[pmed.BestSolutionIndex]; } } //timeelapsed = pmed.GetTotalElapsedTime(); //setpofsol = pmed.CheckPofSolutions(false); } } //salvo i risultati del meglio Console.Write("\r\nSalvo i risultati..."); swBatchOut.WriteLine("{4} : Solution = {0} --- Wrapper = {1} --- TotTime = {2} --- N = {3} CheckSetP = {5}", bestsol, isbestwrap, timeelapsed, setN[j], nomep, setpofsol); swBatchOut.Flush(); Console.WriteLine("ok"); } return(true); }