我正在嘗試爲呼叫中心創建一個計劃,在該計劃中,我嘗試在高通話期間儘量提高工作人員的人數,並在低期間儘量減少。爲簡單起見,它看起來是這樣的:Microsoft Solver Foundation在添加約束時引發ArgumentNullException
我有以下代碼:
var startTimes = BuildStartTimes();
var employees = BuildEmployees();
ConstraintSystem solver = ConstraintSystem.CreateSolver();
CspDomain wrkTime = solver.CreateIntegerSet(startTimes);
CspTerm[][] scheduleMatrix = solver.CreateVariableArray(wrkTime, "Schedule", employees.Length, startTimes.Length);
//iterate through times adding column constraints
for (int i = 0; i < startTimes.Length -1; i++)
{
//add constraint for employees numbers
for (int emp = 0; emp < employees.Length; emp++)
{
//for simplistic sake, the Ids i to 9 represent employee Ids
scheduleMatrix[emp][i].Model.CreateIntegerSet(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
}
solver.AddConstraints(
//add constraint that the employee can be added just once
solver.GreaterEqual(NumberOfWorkersRequiredForShift(i, employees), GetColumn(scheduleMatrix, i)),
//employee can only list once
solver.Unequal(GetColumn(scheduleMatrix,i))
);
}
for (int i = 0; i < employees.Length -1; i++)
{
solver.AddConstraints(
//employee can only listed nine consecutive 36 times maximum
//4 * 15 minutes * 9 hours == 4 * 9 == 36
solver.Equal(36,GetRow(scheduleMatrix,i))
);
}
private static CspTerm[] GetColumn(CspTerm[][] matrix, int column)
{
CspTerm[] slice = new CspTerm[matrix.Length];
for (int row = 0; row < matrix.Length; row++)
slice[row] = matrix[row][column];
return slice;
}
private static CspTerm[] GetRow(CspTerm[][] matrix, int row)
{
CspTerm[] slice = new CspTerm[matrix[0].Length];
for (int col = 0; col < matrix.Length; col++)
slice[col] = matrix[row][col];
return slice;
}
我得到一個ArgumentNullException上限制員工到9小時(例如4十五個約束分鐘部分* 9小時= 36次)。
這裏的堆棧跟蹤:
在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.ValidateInputs(CspTerm [] 輸入)在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.Equal(的Int32 CSPCallCenterDemo \ CSPCallCenterDemo \ Program.cs:line 40 at CSPCallCenterDemo.Program.Main(String [] args)在C:\ Users \ wdniels \ Documents \ Visual Studio 中的常量CspTerm []輸入) .AppD omain._nExecuteAssembly(RuntimeAssembly組件, 字串[] args)在System.AppDomain.ExecuteAssembly(字符串 assemblyFile,證據assemblySecurity,字串[] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 的System.Threading .ThreadHelper.ThreadStart_Context在 System.Threading.ExecutionContext.RunInternal(對象狀態)(的ExecutionContext 的ExecutionContext,ContextCallback回調,對象的狀態,布爾 preserveSyncCtx)在 System.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回調,對象狀態,布爾 preserveSyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext 的ExecutionContext,ContextCallback回調,對象狀態)在 System.Threading.ThreadHelper.ThreadStart()
也沒有人知道如何添加,以確保該僱員將努力約束連續36 間隔15分鐘?
GetRow()中有一個明顯的錯字。代碼防守並改用slice.Length。在幾個斷言中拋出,驗證鋸齒陣列數組全都具有相同的長度並且它們的元素不爲空也不會傷害它們。 – 2014-10-26 22:53:52