/// <summary> /// I used this Gurobi model to calculate the fixed point baseline. /// </summary> public mae_sdo() { string path = @"C:\Users\Roman Bolzern\Desktop\D4\neu\meta_data_training.csv"; var lines = File.ReadLines(path).ToArray(); GRBEnv env = new GRBEnv(); GRBModel m = new GRBModel(env); var scale = 1e9; var y = m.AddVar(1e-9 * scale, 1e-2 * scale, 0d, GRB.CONTINUOUS, "y"); var obj = new GRBLinExpr(); for (int i = 1; i < lines.Length; i++) { var diff = double.Parse(lines[i].Split(',')[3]) * scale - y; var diffinput = m.AddVar(-1e-2 * scale, 1e-2 * scale, 0d, GRB.CONTINUOUS, "diffinput"); m.AddConstr(diffinput == diff); var diffres = m.AddVar(0, 1e-2 * scale, 0d, GRB.CONTINUOUS, "diffres"); m.AddGenConstrAbs(diffres, diffinput, "diffAbs"); obj += diffres; } m.SetObjective(obj, GRB.MINIMIZE); m.Optimize(); Console.WriteLine($"Objective: {((GRBLinExpr)m.GetObjective()).Value / scale}"); Console.WriteLine($"fixed point: {y.X / scale}"); }
public override double GetObjective(object solver) { GRBModel grbSolver = solver as GRBModel; if (grbSolver == null) { return(0.0); } return(((GRBLinExpr)grbSolver.GetObjective()).Value); }
public override bool SetObj(object solver, int Column, double Value) { GRBModel grbSolver = solver as GRBModel; if (grbSolver == null) { return(false); } GRBLinExpr exp = grbSolver.GetObjective() as GRBLinExpr; exp.AddTerm(Value, exp.GetVar(Column)); return(true); }