void WriteVariable(string sInstanceID, OleDbConnection connect, GAMSDatabase db, string varName, params string[] Domains) { try { GAMSVariable var = db.GetVariable(varName); if (Domains.Length != var.Dim) { lsLog.Add("Number of column names does not match the dimension of the variable."); } connect.Open(); // delete table varName if it exists already OleDbCommand cmd = new OleDbCommand("", connect); string query = "delete from Results where InstanceID = '" + sInstanceID + "';"; cmd.CommandText = query; cmd.ExecuteNonQuery(); List <string> lsQueries = new List <string>(); foreach (GAMSVariableRecord rec in var) { query = "insert into Results(InstanceID,"; foreach (string dom in Domains) { query += dom + ", "; } query += "ShipmentValue) values ('" + sInstanceID + "',"; foreach (string key in rec.Keys) { query += "'" + key + "', "; } query += rec.Level + ")"; lsQueries.Add(query); } cmd.CommandText = string.Join(";", lsQueries); cmd.ExecuteNonQuery(); } catch (Exception ex) { lsLog.Add("Error: Failed to write variable to the database." + ex.Message); } finally { connect.Close(); } }
private static void PrintResults(GAMSDatabase db, int instanceIx, bool enforceOrigin) { string ostr = ""; ostr += $"Instance {instanceIx + 1} {(enforceOrigin ? "with" : "w/out")} enforced origin\n"; ostr += $"Delays {GDXUtils.GetLevelsStr(db.GetVariable("v"))}\n"; ostr += $"Costs:\t{db.GetVariable("f").FirstRecord().Level}\n"; int numGoods = db.GetSet("i").NumberRecords; int numComponents = db.GetSet("k").NumberRecords; var z = db.GetVariable("z"); var xint = db.GetVariable("xint"); var x = db.GetVariable("x"); var orders = GetOrders(db.GetVariable("w")); // first good is external source (not from disassembling but instead from order) for (int i = 1; i < numGoods; i++) { for (int k = 0; k < numComponents; k++) { int whenProvided = WhenProvided(x, i, k); ostr += $"i{i + 1},k{k + 1}: Provided at {whenProvided} "; int repairStart = GetRepairStart(z, i, k); if (repairStart >= 0) { ostr += $";; repair starts at {repairStart}"; } bool internallyProvided = InternallyProvided(xint, i, k); if (!internallyProvided) { Order o = orders.First(order => order.K == k); ostr += $";; ordered at {o.T}"; } ostr += "\n"; } } Console.WriteLine(ostr); }