manbet体育手机客户端


fixanddive_vb.vb


“实现一个简单的MIP启发式。狗万app足彩放松模型,根据分数性对变量进行排序,并修正“最接近整数变量的分数变量”中的25%。重复,直到松弛是整数可行的或“线性不可行的”。进口系统进口进口System.Collections.Generic Gurobi类fixanddive_vb”比较类用于排序变量列表基于松弛的fractionality私人类FractionalCompare:实现IComparer (GRBVar)公共函数比较(按值传递v1 GRBVar,按值传递v2 GRBVar)作为整数_实现IComparer (Gurobi.GRBVar)。比较Try Dim sol1 As Double = Math. abs (v1.X) Dim sol2 As Double = Math. abs (v2.X) Dim frac1 As Double = Math. abs (v2.X) Dim frac1 As Double = Math. abs (v1.X) DimAbs (sol1 -数学。Floor(sol1 + 0.5)) Dim frac2 As Double = Math。Abs (sol2 -数学。Floor(sol2 + 0.5)) If frac1 < frac2 Then Return -1 ElseIf frac1 > frac2 Then Return 1 Else Return 0结束WriteLine("错误代码:" & e.ErrorCode & "。" & e.Message)结束尝试返回0结束函数结束类共享子Main(ByVal args As String())长度< 1然后是控制台。WriteLine("Usage: fixanddive_vb filename")返回结束如果尝试' Read model Dim env As New GRBEnv() Dim model As New GRBModel(env, args(0)) 'getvars () If v. vtype <> GRB. If v. vtype <> GRB. If v. vtype <> GRB. If v. vtype <>然后intvars.Add(v) v. vtype = GRB。model.Parameters.OutputFlag = 0 model.Optimize() ' Perform multiple iterations. In each iteration, identify the first ' quartile of integer variables that are closest to an integer value ' in the relaxation, fix them to the nearest integer, and repeat. For iter As Integer = 0 To 999 ' create a list of fractional variables, sorted in order of ' increasing distance from the relaxation solution to the nearest ' integer value Dim fractional As New List(Of GRBVar)() For Each v As GRBVar In intvars Dim sol As Double = Math.Abs(v.X) If Math.Abs(sol - Math.Floor(sol + 0.5)) > 0.00001 Then fractional.Add(v) End If Next Console.WriteLine("Iteration " & iter & ", obj " & _ model.ObjVal & ", fractional " & fractional.Count) If fractional.Count = 0 Then Console.WriteLine("Found feasible solution - objective " & _ model.ObjVal) Exit For End If ' Fix the first quartile to the nearest integer value fractional.Sort(New FractionalCompare()) Dim nfix As Integer = Math.Max(fractional.Count / 4, 1) For i As Integer = 0 To nfix - 1 Dim v As GRBVar = fractional(i) Dim fixval As Double = Math.Floor(v.X + 0.5) v.LB = fixval v.UB = fixval Console.WriteLine(" Fix " & v.VarName & " to " & fixval & _ " ( rel " & v.X & " )") Next model.Optimize() ' Check optimization result If model.Status <> GRB.Status.OPTIMAL Then Console.WriteLine("Relaxation is infeasible") Exit For End If Next ' Dispose of model and env model.Dispose() env.Dispose() Catch e As GRBException Console.WriteLine("Error code: " & e.ErrorCode & ". " + e.Message) End Try End Sub End Class