ilog opl 存取外部文件
来源:互联网 发布:淘宝 补全会员名 编辑:程序博客网 时间:2024/06/06 08:26
Writing data to an external file using OPL script
Question
How do I write data to an external file using OPL script?
Answer
The following sample .mod file creates a trivial model, and then writes the input data along with the optimal (objective and variable) values to an external file called modelRun.txt in a post-processing execute block. In its current form, the external file will be created (if not already present) in the same folder as that of the project, but the IloOplOutputFile
can also take an absolute path location as needed by a user:
/**writeExternal.mod**/
range r=1..5;
dvar int+ x[r];
int y[i in r]=i;
minimize sum(i in r) x[i];
subject to{
forall(i in r)
x[i]>=y[i];
}
execute{
var ofile = new IloOplOutputFile("modelRun.txt");
ofile.writeln("Data:");
for(var i in thisOplModel.r){
ofile.writeln("y["+i+"]="+thisOplModel.y[i]);
}
ofile.writeln("Optimal objective value="+cplex.getObjValue());
ofile.writeln("Optimal variable values:");
for(i in thisOplModel.r){
ofile.writeln("x["+i+"]="+thisOplModel.x[i]);
}
ofile.close();
}
As an alternative, the main block of an OPL model can also be used to do similar operations. The following sample shows one such implementation, where the internal, external & solution data (without iterating through the elements) is written out to an external file:
/**writeExternal.mod**/
range r = 1..5;
int y[i in r] = i;
dvar int+ x[r];
minimize sum(i in r) x[i];
subject to {
forall(i in r)
x[i] >= y[i];
}
main {
thisOplModel.generate();
cplex.solve();
var ofile = new IloOplOutputFile("modelRun.txt");
ofile.writeln(thisOplModel.printExternalData());
ofile.writeln(thisOplModel.printInternalData());
ofile.writeln(thisOplModel.printSolution());
ofile.close();
}
Reference : http://www-01.ibm.com/support/docview.wss?uid=swg21508158
- ilog opl 存取外部文件
- ILOG CPLEX OPL 编程,使用心得
- ILOG OPL的一个简单应用——解决运输问题、转运问题
- 文件存取
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 创建顺序存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 数据库中存取文件
- 利用数据库存取文件
- 文件存取图片
- First
- ubuntu SVN命令大全
- ubuntu 启动时 设置多个ip 修改mac 网关 。。。
- 四级之翻译备考
- _CRT_SECURE_NO_WARNINGS
- ilog opl 存取外部文件
- HDU-2063 过山车
- stagefright与opencore对比
- Ogre Timer 类 解析
- extends Thread 与 implements Runnable 的区别
- 视频采集方式比较
- mysql command
- XCode调试技巧之EXC_BAD_ACCESS中BUG解决
- 设计模式——模板模式_Template Pattern