2

我正在尝试为呼叫中心创建一个时间表,我试图在高呼叫期间最大化员工并在低呼叫期间最小化。为简单起见,它看起来像:

简单的呼叫中心时间表

我有以下代码:

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;
}

我在将员工限制为 9 小时(例如 4 15 分钟部分 * 9 小时 = 36 次)的约束条件下收到 ArgumentNullException。

这是堆栈跟踪:


在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.ValidateInputs(CspTerm[] 输入) 在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.Equal(Int32 常数, CspTerm[] 输入) 在 CSPCallCenterDemo.Program.Main(String[] args) 在 c: \Users\wdniels\Documents\Visual Studio 2012\Projects\CSPCallCenterDemo\CSPCallCenterDemo\Program.cs:System.AppDomain._nExecuteAssembly 的第 40 行(RuntimeAssembly 程序集,String[] args)在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity , String[] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback 回调, Object state, Boolean preserveSyncCtx ) 在 System.Threading。ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()


还有谁知道我如何添加一个约束来确保员工将连续工作 3615 分钟的间隔?

4

1 回答 1

3

你得到 ArgumentException 因为你 GetRow 代码没有完全填满 CspTerm。你必须像这样重写它:

    private static CspTerm[] GetRow(CspTerm[][] matrix, int row)
    {
        CspTerm[] slice = new CspTerm[matrix[0].Length];
        for (int col = 0; col < matrix[0].Length; col++)
            slice[col] = matrix[row][col];

        return slice;
    }
于 2014-10-26T19:39:02.250 回答