Visual Studio 2010 で VB.NET を使用して Microsoft Solver Foundation を使用して最適化モデルを作成しようとしています。パフォーマンス評価。潜在的な従業員ごとに決定変数を作成しました。不採用決定の場合は 0、採用決定の場合は 1 に設定されます。
従業員の総コスト、総パフォーマンス スコア、または各タイプの従業員の合計を計算しようとすると、決定変数にまだ値がないことを示すエラーが表示されます。
各制約で従業員データベース全体のすべての決定変数を個別にリストせずに、これらの制約を (おそらくループで) 追加する簡単な方法はありますか?
ここに私が取り組んでいるコードがあります。
Dim myEmployee As Employee
Dim context As SolverContext = SolverContext.GetContext()
Dim model As Model = context.CreateModel()
For Each myEmployee In employeeList
If myEmployee.Type = "Bartender" Then
Dim BartenderHire As New Decision(Domain.IntegerRange(0, 1), myEmployee.ID)
barDecisionList.Add(BartenderHire)
ElseIf myEmployee.Type = "Host(ess)" Then
Dim HostHire As New Decision(Domain.IntegerRange(0, 1), myEmployee.ID)
hostDecisionList.Add(HostHire)
ElseIf myEmployee.Type = "Waiter/Waitress" Then
Dim WaiterHire As New Decision(Domain.IntegerRange(0, 1), myEmployee.ID)
waitDecisionList.Add(WaiterHire)
End If
Next
For i = 0 To barDecisionList.Count - 1
model.AddDecision(barDecisionList.Item(i))
Next
For i = 0 To hostDecisionList.Count - 1
model.AddDecision(hostDecisionList.Item(i))
Next
For i = 0 To waitDecisionList.Count - 1
model.AddDecision(waitDecisionList.Item(i))
Next
'Calculate cost of hired employees.
Dim cost As Double
cost = 0
For i = 0 To model.Decisions.Count - 1
Dim thisEmployee As Employee = employeeList.Item(i)
cost = cost + (model.Decisions(i).ToDouble * thisEmployee.Wage * 6)
Next
'Calculate total score of hired employees.
Dim totalScore As Double
totalScore = 0
For i = 0 To model.Decisions.Count - 1
Dim thisEmployee As Employee = employeeList.Item(i)
totalScore = totalScore + (model.Decisions(i).ToDouble * thisEmployee.Score)
Next
'Calculate total bartenders hired.
Dim barSum As Integer
barSum = 0
For i = 0 To barDecisionList.Count - 1
barSum = barSum + barDecisionList.Item(i)
Next
'Calculate total waiters hired.
Dim waitSum As Integer
waitSum = 0
For i = 0 To waitDecisionList.Count - 1
waitSum = waitSum + waitDecisionList.Item(i)
Next
'Calculate total hosts hired.
Dim hostSum As Integer
hostSum = 0
For i = 0 To hostDecisionList.Count - 1
hostSum = hostSum + hostDecisionList.Item(i)
Next
'Add constraints
model.AddConstraint("Bartenders_Required", barSum = bartendersRequired)
model.AddConstraint("WaitStaff_Required", waitSum = waitersRequired)
model.AddConstraint("Hosts_Required", hostSum = hostsRequired)
model.AddConstraint("Budget", cost <= budget)
model.AddGoal("Total_Score", GoalKind.Maximize, totalScore)
Dim solution As Solution = context.Solve(New SimplexDirective())
Dim report As Report = solution.GetReport
For i = 0 To model.Decisions.Count - 1
solutionList.Add(model.Decisions(i))
Next