Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 微软Sover基金会在添加约束时抛出了AgMutnull异常_C#_Constraints_Ms Solver Foundation - Fatal编程技术网

C# 微软Sover基金会在添加约束时抛出了AgMutnull异常

C# 微软Sover基金会在添加约束时抛出了AgMutnull异常,c#,constraints,ms-solver-foundation,C#,Constraints,Ms Solver Foundation,我试图为呼叫中心制定一个时间表,在呼叫高峰时段尽量增加员工人数,在低谷时段尽量减少员工人数。为了简单起见,它看起来像: 我有以下代码: var startTimes = BuildStartTimes(); var employees = BuildEmployees(); ConstraintSystem solver = ConstraintSystem.CreateSolver(); CspDomain wrkTime = solver.CreateIntegerSet(startTim

我试图为呼叫中心制定一个时间表,在呼叫高峰时段尽量增加员工人数,在低谷时段尽量减少员工人数。为了简单起见,它看起来像:

我有以下代码:

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;
}
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);
//迭代添加列约束的时间
对于(int i=0;i
我得到一个例外,限制员工9小时(例如,4 15分钟部分*9小时=36次)

以下是堆栈跟踪:


在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.ValidateInputs(CspTerm[] 输入)在 Microsoft.SolverFoundation.Solvers.ConstraintSystem.Equal(Int32 CSPCallCenterDemo.Program.Main(字符串[])处的常量,CspTerm[]输入 c:\Users\wdniels\Documents\visualstudio中的参数 2012\Projects\CSPCallCenterDemo\CSPCallCenterDemo\Program.cs:第40行 在System.AppDomain.\u下一个安全程序集(运行时程序集, System.AppDomain.ExecuteAssembly处的字符串[]args(字符串 assemblyFile,证据assemblySecurity,字符串[]args)位于 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()位于 位于的System.Threading.ThreadHelper.ThreadStart_上下文(对象状态) System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback回调、对象状态、布尔值 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback回调、对象状态)位于 System.Threading.ThreadHelper.ThreadStart()



还有谁知道我如何添加一个约束,确保员工以36连续15分钟的间隔工作吗?

由于GetRow代码没有完全填满术语,您会得到ArgumentException。 你必须这样重写它:

    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;
    }
私有静态CspTerm[]GetRow(CspTerm[][]矩阵,int行)
{
CspTerm[]切片=新CspTerm[矩阵[0]。长度];
对于(int col=0;col<矩阵[0]。长度;col++)
切片[col]=矩阵[row][col];
返回片;
}

GetRow()中有一个明显的输入错误。防御性地编码并使用slice.Length。抛出几个断言来验证交错数组都具有相同的长度,并且它们的元素不为null,这也不会有任何影响。