feasopt_vb.vb


版权2023、Gurobi优化LLC狗万app足彩“这个例子从文件读取MIP模型,增加了人工的每个约束变量,然后最小化“人工变量之和。解决方案与目标零对应输入模型的可行解。我们还可以使用FeasRelax特性。在这个例子中,我们使用minrelax = 1,即返回模型找到了一个解决方案的优化,最大限度地减少最初的目标,但只有其中的解决方案,最大限度地减少人工变量的总和。主要进口Gurobi进口系统类feasopt_vb共享子(按值传递参数是字符串())如果参数。长度< 1然后控制台。WriteLine(用法:feasopt_vb文件名)返回结束如果尽可能暗env新GRBEnv()暗feasmodel新GRBModel (env, args (0))“创建一个副本使用FeasRelax特性后暗feasmodel1新GRBModel (feasmodel)“feasmodel明确目标。SetObjective(新GRBLinExpr ())“添加松弛变量模糊c作为GRBConstr () = feasmodel.GetConstrs()因为我作为c整数= 0。长度- 1昏暗的感觉为Char = c (i)。Sense If sense <> ">"c Then Dim constrs As GRBConstr() = New GRBConstr() {c(i)} Dim coeffs As Double() = New Double() {-1} feasmodel.AddVar(0.0, GRB.INFINITY, 1.0, GRB.CONTINUOUS, _ constrs, coeffs, _ "ArtN_" & c(i).ConstrName) End If If sense <> "<"c Then Dim constrs As GRBConstr() = New GRBConstr() {c(i)} Dim coeffs As Double() = New Double() {1} feasmodel.AddVar(0.0, GRB.INFINITY, 1.0, GRB.CONTINUOUS, _ constrs, coeffs, _ "ArtP_" & c(i).ConstrName) End If Next ' Optimize modified model feasmodel.Optimize() feasmodel.Write("feasopt.lp") ' Use FeasRelax feature */ feasmodel1.FeasRelax(GRB.FEASRELAX_LINEAR, true, false, true) feasmodel1.Write("feasopt1.lp") feasmodel1.Optimize() ' Dispose of model and env feasmodel1.Dispose() feasmodel.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: " & e.ErrorCode & ". " & e.Message) End Try End Sub End Class