- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 C++ Concert Cplex 有问题。我正在尝试重新创建最短路径问题。输出到文本文件是:
Minimize
obj: 2 x_12 + x_13 + 2 x_21 + x_24 + x_31 + 3 x_34 + x_42 + 3 x_43 + x9
Subject To
c1: x_12 + x_13 - x_21 - x_31 + x_14 - x_41 = 1
c2: - x_12 + x_21 + x_24 - x_42 + x_23 - x_32 = 0
c3: - x_13 + x_31 + x_34 - x_43 - x_23 + x_32 = 0
c4: - x_24 - x_34 + x_42 + x_43 - x_14 + x_41 = -1
Bounds
x9 = 0
End
然后我使用下面的代码来获得解决方案:
IloCplex spp(model);
spp.setParam(IloCplex::RootAlg, IloCplex::AutoAlg);
spp.solve();
IloArray<IloNumArray> vals(env);
env.out() << "Solution status = " << spp.getStatus() << endl;
env.out() << "Solution value = " << spp.getObjValue() << endl;
env.out() << "Values x = " << vals << endl;
但是我不断得到的输出是:
Solution status = Optimal
Solution value = 0
Values x = []
有人知道我的程序有什么问题吗?谢谢
编辑:
我的模型是在程序本身中构建的,这是第一部分:
IloEnv env;
IloModel model(env);
IloArray<IloNumVarArray> x(env);
IloRangeArray c(env);
IloInt nnodes = G.size();
IloInt i, j;
IloEnv env = model.getEnv();
//SHORTEST PATH PROBLEM
for (i = 0; i < nnodes; i++){ //x decision variables
x.add(IloNumVarArray(env, nnodes, 0, IloInfinity));
}
for (i = 0; i < nnodes; i++){
for (j = 0; j < nnodes; j++){
stringstream sts;
sts << "x_" << i + 1 << j + 1;
x[i][j].setName(sts.str().c_str()); //SET NAMES
}
}
//set objective min sum_(all ij)[c_ij][x_ij]
IloExpr obj(env);
for (i = 0; i < nnodes; i++){
for (j = 0; j < nnodes; j++){
obj += G[i][j] * x[i][j];
}
}
model.add(IloMinimize(env, obj));
obj.end();
//constraints sum_j[x_ij]-sum_j[x_ji] = 1 for s, -1 for t, or 0
for (i = 0; i < nnodes; i++){
int ss = 0;
if (i == s) ss = 1;
if (i == t) ss = -1;
IloExpr sum1(env);
IloExpr sum2(env);
for (j = 0; j < nnodes; j++){
sum1 += x[i][j];
sum2 += x[j][i];
}
c.add(sum1 - sum2 == ss);
sum1.end();
sum2.end();
}
model.add(c);
//solving---------------------------------------------------------
IloCplex spp(model);
//write to file
spp.exportModel("model1.lp");
spp.solve();
最佳答案
显然您没有从文件中读取模型。这是一个 example .所以在你的情况下:
#include <ilcplex/ilocplex.h>
ILOSTLBEGIN
int main (int argc, char **argv)
{
IloEnv env;
try {
IloModel model(env);
IloCplex cplex(model);
IloObjective obj;
IloNumVarArray var(env);
IloRangeArray con(env);
cplex.importModel(model, "tmp.lp", obj, var, con);
cplex.extract(model);
// Optimize the problem and obtain solution.
if ( !cplex.solve() ) {
env.error() << "Failed to optimize LP" << endl;
throw(-1);
}
IloNumArray vals(env);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, con);
env.out() << "Slacks = " << vals << endl;
cplex.getDuals(vals, con);
env.out() << "Duals = " << vals << endl;
cplex.getReducedCosts(vals, var);
env.out() << "Reduced Costs = " << vals << endl;
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
} // END main
tmp.lp 是您的 LP 模型文件。运行我得到的这段代码
Tried aggregator 1 time.
LP Presolve eliminated 3 rows and 12 columns.
Aggregator did 1 substitutions.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.01 ticks)
Solution status = Optimal
Solution value = 0
Values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
Slacks = [0, 0, 0, 0]
Duals = [1, 0, 0, 1]
Reduced Costs = [1, 0, 3, 2, 2, 4, 0, 2, 1, 0, 0, 0, 0]
关于c++ - 复杂模型 : no solution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38278871/
我的构建菜单包含两个构建选项: 构建解决方案 构建MyProjectName 如果我选择Build Solution(然后是Debug,Start Debugging (F5)),运行的可执行文件不包
我有一个带有一些输入字段的表单。这些输入字段具有指定的背景渐变,如下所示: input { background: #00b7ea; background: url(data:imag
现在这个遗留代码是多个项目,每个项目都有自己的解决方案。每个项目通过它编译的 dll 引用另一个项目。要让主项目运行,您必须以正确的顺序进行 10 多个单独的构建。 我试图解释如何将所有项目移动到一个
我在 Visual Studio 2013 中处理我的项目,我错误地点击了 Rebuild Solution。我收到以下异常,我不知道如何解决它。请建议。 Server Error in '/' Ap
class solution { void table(final int n) { for (int i = 1; i <= 10; i++) { S
我非常需要了解如何使用 Visual Studio 2010 在 c# 中管理一些非常基本的体系结构问题,而且我在教科书和网站上寻找解决方案时遇到了一些困难。假设我有一个 MyWinForm.sln
我有 Java 背景,正在尝试从 C# 开始。 我想用 C# 创建一个将在其他解决方案中使用的库。在 Eclipse 中,只需创建一个 jar 并将其添加到类路径中即可。我知道VS2013中的每个项目
在我目前的工作中,我需要打开 3 个不同的解决方案,构建并运行它们。是否有任何脚本可以像我单击 Web 服务的“构建解决方案”或“启动”或“Google Chrome”一样执行工作人员? 谢谢。 最佳
有什么方法可以告诉Visual Studio 2005的解决方案资源管理器在svn-checkout后第一次打开解决方案时不要扩展所有项目? 编辑: 感谢您指出 PowerCommands。当我使用带
我的 Visual Studio 解决方案的 Subversion 存储库中有以下目录: 项目名称 标签 分支机构 后备箱 我的解决方案.sln MyProject1(目录) MyProject2(目
我刚刚使用 Update 2 更新了 Visual Studio 2015。 现在,经过几个小时的正常工作,我收到:“检测到内存不足。对此解决方案禁用了完整的解决方案分析。”出现在我的 VS2015
在 Visual Studio Code 中,单击我的测试项目中的“调试测试”代码镜头链接: 导致错误信息: MSBUILD : error MSB1011: Specify which projec
我是Docker的新手,正在尝试为ASP.NET Core应用程序创建Dockerfile。有人可以建议我需要哪些更改吗? 这是我的Dockerfile: FROM microsoft/dotnet:
我的入门类(class)的这个实验要求我们以 pig 拉丁语返回任何用户输入。当我运行它并在控制台中输入任何字符串时,我似乎不断收到的错误是: java.lang.StringIndexOutO
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 11 个月前关闭。 Improv
我的 C++ Concert Cplex 有问题。我正在尝试重新创建最短路径问题。输出到文本文件是: Minimize obj: 2 x_12 + x_13 + 2 x_21 + x_24 + x_
有时,当我浏览我的头文件时,我想在 (doxygen) 文档中添加一些小东西。这可能是关于使用某些函数参数的快速说明,或者只是修复了一个小错字。 但后来我想:哦不,这会在下一个 make 调用时触发重
我正在使用缺少 findall 的高阶 Prolog 变体. 还有一个关于实现我们自己的问题 findall这里:Getting list of solutions in Prolog . 低效的实现
如果您的应用程序必须对大尺寸对象(> 85000 字节)进行大量分配/取消分配,则最终会导致内存碎片,并且您的应用程序将抛出内存不足异常。 这个问题有什么解决方案,还是CLR内存管理的限制? 最佳答案
我是一名优秀的程序员,十分优秀!