/// <summary> /// /// </summary> public Form1() { InitializeComponent(); sw = new SplashWindow(true, true, true); sw.Show(); computeToolStripMenuItem.Enabled = false; WriteTextCallBack = new PMed.WriteDelegate(ConsoleAppendText); ConsoleAppendTextCallBack = new _ConsoleAppendTextCallBack(ConsoleAppendText); UpdateStatusBarCallBack = new _UpdateStatusBarCallBack(UpdateStatusBar); UpdateSolutionVieverCallBack = new _UpdateSolutionVieverCallBack(UpdateSolutionViever); SolutionViewerClearCallBack = new _SolutionViewerClearCallBack(SolutionViewerClear); try { pm = new PMed3(WriteTextCallBack, 1, "PMedProb", false, false); pm.Progress += OnProgressReport; } catch (DllNotFoundException e) { MessageBox.Show(String.Format("Dll CoinOR not found!!!\r\nCannot Compute Set Covering (Step 3)\r\n\r\n{0}", e), "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(e.Message); this.Close(); } }
private void InitService() { CurrentDir = Directory.GetCurrentDirectory(); String AppDir = AppDomain.CurrentDomain.BaseDirectory; selectfile_index = -1; M = 0; Exception _e = null; ReadConfigFile(AppDir); if (ProblemDir.Length == 0) { ProblemDir = AppDir + DefaultProblemDir; } if (LogDir.Length == 0) { LogDir = AppDir + LogFileName; } //un log al giorno LogDir += "_" + DateTime.Today.Year + DateTime.Today.Month + DateTime.Today.Day; //un log al mese //LogDir += "_" + DateTime.Today.Year + DateTime.Today.Month; try { isfs = new FileStream(LogDir, FileMode.Append); } catch (Exception e) { _e = e; isfs = new IsolatedStorageFileStream(LogFileName, FileMode.Append); } sw = new StreamWriter(isfs); sw.AutoFlush = true; sw.WriteLine("\r\nP - Median Library WCF Service LOG file... DATE : {0} - TIME {1}", DateTime.Now.Date, DateTime.Now.TimeOfDay); if (_e != null) { sw.WriteLine("r\nException ERRRO : {0}", _e.Message); } try { pm = new PMed3(sw.Write, 1, "PMedWCFSerProb"); pm_inited = true; } catch (Exception e) { //... pm_inited = false; sw.WriteLine("Errore PMedLib!"); sw.WriteLine("{0}", e.Message); } }
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 void InitService() //{ // CurrentDir = Directory.GetCurrentDirectory(); // String AppDir = AppDomain.CurrentDomain.BaseDirectory; // selectfile_index = -1; // M = 0; // try // { // Exception _e = null; // if (!ReadConfigFile(AppDir)) // { // if (ProblemDir.Length == 0) // ProblemDir = AppDir + DefaultProblemDir; // } // if (LogDir.Length == 0) // isfs = new IsolatedStorageFileStream(LogFileName, FileMode.Append); // else // { // try // { // //FileIOPermission fperm = new FileIOPermission(FileIOPermissionAccess.Write, LogDir); // //if(fperm.IsUnrestricted()) // if (!File.Exists(LogDir)) // isfs = new FileStream(LogDir, FileMode.Create); // else // isfs = new FileStream(LogDir, FileMode.Append); // } // catch (Exception e) // { // _e = e; // isfs = new IsolatedStorageFileStream(LogFileName, FileMode.Append); // } // } // sw = new StreamWriter(isfs); // sw.AutoFlush = true; // sw.WriteLine("\r\nP - Median Library Web Services LOG file... DATE : {0} - TIME {1}", DateTime.Now.Date, DateTime.Now.TimeOfDay); // if (LogDir.Length == 0) // sw.WriteLine("\r\n\r\n Error directory for logs doesn't exist!!!"); // if (_e != null) // sw.WriteLine("r\nException ERRRO : {0}", _e.Message); // try // { // //codice per fartrovare la dll .... // //var path = Environment.GetEnvironmentVariables(); // //System.Environment.SetEnvironmentVariable("Path", path["Path"] + ";" + DllDir); // pm = new PMed3(sw.Write, 1, "PMedWebSerProb"); // pm_inited = true; // } // catch (Exception e) // { // //... // pm_inited = false; // sw.WriteLine("Errore PMedLib!"); // sw.WriteLine("{0}", e.Message); // } // } // catch (Exception ex) // { // //.... // } //} #endregion private void DeInitService() { pm = null; pm_inited = false; if (sw != null) { sw.Close(); } if (isfs != null) { isfs.Close(); } }
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 static void BatchTests(String args0) { int m = 0; int M = 0; //int sol_i=3; //int i; //int N = 100; String BatchOut = "BatchOut-" + DateTime.Now.Date + "_" + DateTime.Now.TimeOfDay + ".txt"; BatchOut = BatchOut.Replace("/", "-"); BatchOut = BatchOut.Replace(":", "_"); //fsBatchIn = new FileStream("Batch.txt", FileMode.Open); fsBatchIn = new FileStream(args0, FileMode.Open); srBatchIn = new StreamReader(fsBatchIn); //fsBatchOut = new FileStream("BatchOut.txt", FileMode.Create); fsBatchOut = new FileStream(BatchOut, FileMode.Create); swBatchOut = new StreamWriter(fsBatchOut); swBatchOut.AutoFlush = true; pmed = new PMed3(Console.Write, 1); swBatchOut.WriteLine("Batch Output Date/Time : {0} - {1}", DateTime.Now.Date, DateTime.Now.TimeOfDay); while (!srBatchIn.EndOfStream) { string filein = srBatchIn.ReadLine().Trim(); if (filein == "") { break; } swBatchOut.Write("loading {0} --- nodes ", filein); //aggiunto il costruttore, reinitializzo l'oggetto ad ogni nuovo file, //perchè coinor ha dei problemi nella gestione della memoria quando si hanno //matrici molto grandi. //dovuto al fatto di bugs a coinor? //+ precisamente sta in CoinBigIndex che non è implementato in tutti i sotto progetti dell //libreria. //e coin.dll in x64 non funziona correttamente... pmed = new PMed3(Console.Write, 1); pmed.ProblemType = eProblemType.SetPartitioning; if (!LoadPmedProb(filein, ref m, true)) { swBatchOut.WriteLine("\r\nCannot load {0} --- m = {1}\r\n", filein, m); } else { M = m; if ((m > -1)) { m = 1; } for (; m <= M; m++) { //per Capacitated. LoadPmedProb(filein, ref m, false); swBatchOut.WriteLine("{0} - p {1} - m {2}", pmed.nVerteces, pmed.p, m); ComputeBestof3Sol(filein); } if (m == -1) //uncap { swBatchOut.WriteLine("{0} - p {1}", pmed.nVerteces, pmed.p); ComputeBestof3Sol(filein); } } swBatchOut.Flush(); } time.Stop(); swBatchOut.WriteLine("\r\nFinish All batch, time elapsed {0}", time.Elapsed); swBatchOut.Close(); fsBatchOut.Close(); srBatchIn.Close(); fsBatchIn.Close(); }