facility_vb.vb


“版权所有2023,Gurobi O狗万app足彩ptimization, LLC”“设施位置:一家公司目前将其产品从5个工厂运往4个仓库。狗万滚球球该公司正在考虑关闭一些工厂以降低成本。为了尽量减少运输和固定成本,公司应该关闭哪些工厂?狗万滚球球基于前线系统的一个例子:“http://www.solver.com/disfacility.htm”经许可使用。手机万博登录进口系统进口Gurobi类facility_vb共享子Main()尝试在成千上万的仓库需求单位的需求双()= New双(){14日,15日,18日20}的工厂生产能力在昏暗的身份双()= New双(){20日,22日,17日,19日,18日}的固定成本为每个工厂昏暗FixedCosts双()= New双(){12000、15000、17000、13000、16000年_}的运输成本每千单位昏暗TransCosts作为双新双(,)(,)={{4000、2000、3000、2500、4500},_{2500, 2600, 3400, 3000, 4000}, _{1200, 1800, 2600, 4100, 3000}, _{2200, 2600, 3100, 3700, 3200}} '工厂和仓库的数量Dim nPlants As Integer =容量。长度Dim nwarehousing As Integer =需求。Length ' Model Dim env As New GRBEnv() Dim Model As New GRBModel(env) Model。工厂开放决策变量:如果工厂p是开放的,则open(p) == 1。Dim open As GRBVar() = New GRBVar(nPlants - 1) {} For p As Integer = 0 To nPlants - 1 open(p) = model。AddVar(0,1,固定成本(p), GRB。二进制,“打开”& p)下一个“运输决策变量:从工厂p到仓库w Dim运输作为GRBVar(,) =新的GRBVar(nlibraries - 1, nPlants - 1) {} w As Integer = 0到nlibraries - 1 For p As Integer = 0到nPlants - 1运输(w, p) =模型。AddVar(0,伽马射线爆发。INFINITY, _ TransCosts(w, p), GRB.CONTINUOUS, _ "Trans" & p & "." & w) Next Next ' The objective is to minimize the total fixed and variable costs model.ModelSense = GRB.MINIMIZE ' Production constraints ' Note that the right-hand limit sets the production to zero if ' the plant is closed For p As Integer = 0 To nPlants - 1 Dim ptot As GRBLinExpr = 0 For w As Integer = 0 To nWarehouses - 1 ptot.AddTerm(1.0, transport(w, p)) Next model.AddConstr(ptot <= Capacity(p) * open(p), "Capacity" & p) Next ' Demand constraints For w As Integer = 0 To nWarehouses - 1 Dim dtot As GRBLinExpr = 0 For p As Integer = 0 To nPlants - 1 dtot.AddTerm(1.0, transport(w, p)) Next model.AddConstr(dtot = Demand(w), "Demand" & w) Next ' Guess at the starting point: close the plant with the highest ' fixed costs; open all others ' First, open all plants For p As Integer = 0 To nPlants - 1 open(p).Start = 1.0 Next ' Now close the plant with the highest fixed cost Console.WriteLine("Initial guess:") Dim maxFixed As Double = -GRB.INFINITY For p As Integer = 0 To nPlants - 1 If FixedCosts(p) > maxFixed Then maxFixed = FixedCosts(p) End If Next For p As Integer = 0 To nPlants - 1 If FixedCosts(p) = maxFixed Then open(p).Start = 0.0 Console.WriteLine("Closing plant " & p & vbLf) Exit For End If Next ' Use barrier to solve root relaxation model.Parameters.Method = GRB.METHOD_BARRIER ' Solve model.Optimize() ' Print solution Console.WriteLine(vbLf & "TOTAL COSTS: " & model.ObjVal) Console.WriteLine("SOLUTION:") For p As Integer = 0 To nPlants - 1 If open(p).X > 0.99 Then Console.WriteLine("Plant " & p & " open:") For w As Integer = 0 To nWarehouses - 1 If transport(w, p).X > 0.0001 Then Console.WriteLine(" Transport " & _ transport(w, p).X & _ " units to warehouse " & w) End If Next Else Console.WriteLine("Plant " & p & " closed!") 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