manbet体育手机客户端


fixanddive_vb.vb


“版权所有,2018,Gurobi优狗万app足彩化,LLC”“实现一个简单的MIP启发式。放松模型,“根据分数对变量进行排序,并修正最接近整数变量的25%的分数变量。”重复,直到松弛是整数可行或“线性不可行”。进口系统进口进口System.Collections.Generic Gurobi类fixanddive_vb”比较类用于排序变量列表基于松弛的fractionality私人类FractionalCompare:实现IComparer (GRBVar)公共函数比较(按值传递v1 GRBVar,按值传递v2 GRBVar)作为整数_实现IComparer (Gurobi.GRBVar)。比较尝试昏暗sol1作为Double = Math. abs (v1.X)昏暗sol2作为Double = Math. abs (v2.X)昏暗frac1作为Double = Math. abs (v2.X)Abs (sol1 -数学。地板(sol1 + 0.5))昏暗frac2作为双重=数学。Abs (sol2 -数学。Floor(sol2 + 0.5)) If frac1 < frac2 Then Return -1 ElseIf frac1 > frac2 Then Return 1 Else Return 0 End If Catch e As GRBException控制台。WriteLine("错误代码:" & e.ErrorCode & "。" & e.Message)结束尝试返回0结束函数结束类共享子Main(ByVal args As String())如果args. String()。长度< 1然后控制台。如果尝试'读取模型昏暗的env作为新的GRBEnv()昏暗的模型作为新的GRBModel(env, args(0)) '收集整型变量并放宽它们Dim intvars As New List(Of GRBVar)() For Each v As GRBVar In model.GetVars() If v. vtype <> GRB. getvars ()然后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