【发布时间】:2017-01-26 05:37:59
【问题描述】:
我的问题是我有 M 个子问题。每个子问题包括 x(双数组)和降低的成本,每次迭代 m 具有不同的值。我想显示在所有子问题中具有最小降低成本的 x。这是我的课:
public class Subproblem
{
public double[,] x { get; set; }
public double ReducedCost { get; set; }
}
到目前为止,我已经可以得到它的最低减少成本和索引。现在我想显示该索引上的 x 值(双数组)。我有这样的代码:
var sub = new List<Subproblem>();
for (int m = 0; m < M; ++m)
{
Subproblem s = new Subproblem();
s.x = new double[DC1, DC1];
s.ReducedCost = model.ObjVal;
for (int i = 0; i < DC1; ++i)
{
for (int j = 0; j < DC1; ++j)
{
s.x[i, j] = x[i, j].X;
}
}
sub.Add(s);
}
double minRC = sub.Min(a => a.ReducedCost);
int minRCIndex = sub.FindIndex((i) => i.ReducedCost == minRC);
Console.WriteLine(sub.x(minRCIndex));
最后一行(Console.WriteLine(sub.x(minRCIndex));)还是有红色下划线,不知道怎么写
【问题讨论】:
-
Console.WriteLine(sub.x[minRCIndex]);
-
@rraszewski,
sub是一个List,不包含x。 -
您的
sub只是m 次引用同一对象的列表