本文整理汇总了C#中Model.SetLogHandler方法的典型用法代码示例。如果您正苦于以下问题:C# Model.SetLogHandler方法的具体用法?C# Model.SetLogHandler怎么用?C# Model.SetLogHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model.SetLogHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Matrix recipe = new DenseMatrix(recipe_data);
using (Model M = new Model("Recipe"))
{
// "production" defines the amount of each product to bake.
Variable production = M.Variable("production",
new StringSet(productnames),
Domain.GreaterThan(0.0));
// The objective is to maximize the total revenue.
M.Objective("revenue",
ObjectiveSense.Maximize,
Expr.Dot(revenue, production));
// The prodoction is constrained by stock:
M.Constraint(Expr.Mul(recipe, production), Domain.LessThan(stock));
M.SetLogHandler(Console.Out);
// We solve and fetch the solution:
M.Solve();
double[] res = production.Level();
Console.WriteLine("Solution:");
for (int i = 0; i < res.Length; ++i)
{
Console.WriteLine(" Number of {0} : {1}", productnames[i], res[i]);
}
Console.WriteLine(" Revenue : ${0}",
res[0] * revenue[0] + res[1] * revenue[1]);
}
}
示例2: lownerjohn_outer
public static double[][] lownerjohn_outer(double[][] x)
{
using( Model M = new Model("lownerjohn_outer") )
{
// Direct log output to the terminal for debugging.
M.SetLogHandler(Console.Out);
int m = x.Length;
int n = x[0].Length;
// Setup variables
Variable t = M.Variable("t", 1, Domain.GreaterThan(0.0));
Variable P = M.Variable("P", new NDSet(n,n), Domain.Unbounded());
Variable c = M.Variable("c", n, Domain.Unbounded());
// (1, P(*xi+c)) \in Q
for (int i = 0; i < m; ++i)
M.Constraint( "qc" + i, Expr.Vstack(Expr.Ones(1), Expr.Sub(Expr.Mul(P,x[i]), c)), Domain.InQCone() );
// t <= det(P)^{1/n}
det_rootn(M, P, t);
// Objective: Maximize t
M.Objective(ObjectiveSense.Maximize, t);
M.Solve();
double[] Plvl = P.Level();
double[] clvl = c.Level();
double[][] Pc = new double[n+1][];
for (int i = 0; i < n; ++i)
{
Pc[i] = new double[n];
System.Array.Copy(Plvl,i*n, Pc[i],0, n);
}
Pc[n] = clvl;
return Pc;
}
}
示例3: lownerjohn_inner
public static double[][] lownerjohn_inner(double[][] A, double[] b)
{
using( Model M = new Model("lownerjohn_inner"))
{
// Direct log output to the terminal for debugging.
M.SetLogHandler(Console.Out);
int m = A.Length;
int n = A[0].Length;
// Setup variables
Variable t = M.Variable("t", 1, Domain.GreaterThan(0.0));
Variable C = M.Variable("C", new NDSet(n,n), Domain.Unbounded());
Variable d = M.Variable("d", n, Domain.Unbounded());
// (bi - ai^T*d, C*ai) \in Q
for (int i = 0; i < m; ++i)
M.Constraint( "qc" + i, Expr.Vstack(Expr.Sub(b[i],Expr.Dot(A[i],d)), Expr.Mul(C,A[i])), Domain.InQCone() );
// t <= det(C)^{1/n}
det_rootn(M, C, t);
// Objective: Maximize t
M.Objective(ObjectiveSense.Maximize, t);
M.Solve();
double[] Clvl = C.Level();
double[] dlvl = d.Level();
double[][] Cres_d = new double[n+1][];
for (int i = 0; i < n; ++i)
{
Cres_d[i] = new double[n];
System.Array.Copy(Clvl,i*n,Cres_d[i],0, n);
}
Cres_d[n] = dlvl;
return Cres_d;
}
}