feasopt_vb.vb


feasopt_vb.vb


本例从文件中读取MIP模型,为每个约狗万app足彩束添加人工变量,然后最小化“人工变量”的总和。目标为零的解对应“输入模型的可行解”。我们也可以使用FeasRelax功能来实现。在这个例子中,我们“使用minrelax=1,即优化返回的模型找到一个解决方案”,使原始目标最小化,但只从这些解决方案中最小化人工变量的和。导入Gurobi导入系统类feasopt_vb共享子Main(ByVal args As String())长度< 1然后控制台。If Try Dim env As New GRBEnv() Dim feasmodel As New GRBModel(env, args(0)将feasmodel1作为新的grb模型(feasmodel)feasmodel明确目标。SetObjective(新GRBLinExpr())”添加松弛变量Dim c As GRBConstr() = feasmodel. getconsts () For i As Integer = 0 To c length - 1 Dim sense As 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