// Reads an instance from the db public GAPclass ReadGAPinstance(string dbpath) { int i, j; List <int> lstCap; List <double> lstCosts; GAPclass G = new GAPclass(); try { using (var ctx = new SQLiteDatabaseContext(dbpath)) { lstCap = ctx.Database.SqlQuery <int>("SELECT cap from capacita").ToList(); G.m = lstCap.Count(); G.cap = new int[G.m]; for (i = 0; i < G.m; i++) { G.cap[i] = lstCap[i]; } lstCosts = ctx.Database.SqlQuery <double>("SELECT cost from costi").ToList(); G.n = lstCosts.Count / G.m; G.c = new double[G.m, G.n]; G.req = new int[G.n]; G.sol = new int[G.n]; G.solbest = new int[G.n]; G.zub = Double.MaxValue; G.zlb = Double.MinValue; for (i = 0; i < G.m; i++) { for (j = 0; j < G.n; j++) { G.c[i, j] = lstCosts[i * G.n + j]; } } for (j = 0; j < G.n; j++) { G.req[j] = -1; // placeholder } } } catch (Exception ex) { Trace.WriteLine("[readGAPinstance] Error:" + ex.Message); } Trace.WriteLine("Fine lettura dati istanza GAP"); return(G); }
// Ricerca locale di istanze GAP public async void OptimizeGAP(string dbPath, string pythonFile, List <String> customers) { GAP = _persistance.ReadGAPinstance(dbPath); if (File.Exists("GAPreq.dat")) { string[] txtData = File.ReadAllLines("GAPreq.dat"); GAP.req = Array.ConvertAll <string, int>(txtData, new Converter <string, int>(i => int.Parse(i))); } else { GAP.req = await ForecastAllCustomerOrderChart(dbPath, pythonFile, customers); File.WriteAllLines("GAPreq.dat", GAP.req.Select(x => x.ToString())); } /* * double zub = GAP.SimpleContruct(); * Trace.WriteLine($"Constructive, zub = {zub}"); * zub = GAP.Opt10(GAP.c); * Trace.WriteLine($"Local search, zub = {zub}"); */ }