当前位置: 首页 > news >正文

Lingo中命令脚本文件使用范例

我们在用lingo的时候有时候会遇到比较繁重的,重复性的工作,手动的单次运行显然耗时耗力,Lingo里的@for函数只能做一些简单的循环,这就要求我们应用脚本文件来简化这些重复性的工作。下面的英文部分是官方手册里给出的一个事例,这里总结下我觉得有用的2个点:

1.脚本文件类型:.ltf 不过脚本文件不会有文件的高亮显示,大家可以先用普通编辑器编辑再拷贝过来。

2.如何解决重复性工作:我们存储数据通常来说都有相对固定的格式。比如饭馆周一到周日每日需要的服务员数,每一项都存在Monday-Sunday的表格里。我们要做的就是巧妙的调用,替换和存储。

示例中把数据存储在ldt格式里了,同理我们也可以调用excel格式(xlsx)文件读取所需数据。替换过程主要用到一个ALTER命令,使用格式为:

 ALTER '新名字'旧名字’ 

这样所有旧名字的字段会被替换成新字段,程序就可以这么循环下去了。

存储数据时也比较有趣,事例中给的是存到text文本中,且给每个文本对应的命名,大家其实也可以用@OLE命令把所有的结果存到一个表里,这也不难。

大家如果看英文觉得麻烦就看看薛金星老师的教材,在第四章LINGO软件与外部文件接口那一章的命令脚本文件那一节。跟官方给的很相似。

示例链接:

http://www.lindo.com/doc/online_help/lingo15_0/a_command_script_example.htm

事例内容:

Once again, we will make use of the staff scheduling model introduced in Using Sets to illustrate the use of a command script. Suppose, instead of one hot dog stand, our operations have expanded and we now have three hot dog stands: Pluto Dogs, Mars Dogs, and Saturn Dogs. Our staffing requirements at the three sites are:

Site

Mon

Tue

Wed

Thu

Fri

Sat

Sun

Pluto

20

16

13

16

19

14

12

Mars

10

12

10

11

14

16

8

Saturn

8

12

16

16

18

22

19

Running staffing models for all three sites is cumbersome(笨重的) and prone to error. We would like to automate the process by constructing a script file that runs all three staffing models automatically. To do this, we construct the following script file:

! Have LINGO echo input to the screen

SET ECHOIN 1

! Suppresses the standard solution report

SET TERSEO 1

! Begins input of a new model

MODEL:

SETS:

  DAYS / MON TUE WED THU FRI SAT SUN/:

   REQUIRED, START;

ENDSETS

 

DATA:

  REQUIRED = @FILE( 'PLUTO.LDT');

  @TEXT( 'PLUTO.TXT') = START;

ENDDATA

 

MIN = @SUM( DAYS( I): START( I));

 

@FOR( DAYS( J):

@SUM( DAYS( I) | I #LE# 5:

 START( @WRAP( J - I + 1, 7)))

  >= REQUIRED( J)

);

 

@FOR( DAYS: @GIN( START));

END

! Solve Pluto Dogs model

GO

! Alter model for Mars

ALTER ALL 'PLUTO'MARS'

! Solve Mars model

GO

! Alter model for Saturn

ALTER ALL 'MARS'SATURN'

! Solve Saturn model

GO

! Restore parameters

SET TERSEO 0

SET ECHOIN 0

Command Script: DOGS.LTF

We use two SET commands to set two of LINGO's parameters. First, we set ECHOIN to 1, which causes LINGO to echo all command script input to the screen. This can be useful when you are trying to debug a script file. Next, we set TERSEO to 1. This causes LINGO to go into terse output mode, which suppresses the default solution report each time we solve a model.

Next, we include the MODEL: command to put LINGO into model input mode. It is important here to remember the MODEL: statement is a command. When LINGO encounters this command in a script file, it reads all subsequent text in the file as model text until it encounters the END command. This model then becomes the current model in memory.

The key feature to note in our model is the data section:

DATA:

  REQUIRED = @FILE( 'PLUTO.LDT');

  @TEXT( 'PLUTO.TXT') = START;

ENDDATA

 

We use the @FILE function to include the staffing requirements from an external file and we use the @TEXT function to send the values of the START attribute to a file.

After the END statement, we have a GO command to solve the model for the Pluto stand. We then include an ALTER command to change all occurrences of 'PLUTO' with 'MARS'. This command will change the data section to (changes in bold):

DATA:

  REQUIRED = @FILE( 'MARS.LDT');

  @TEXT( 'MARS.TXT') = START;

ENDDATA

 

Assuming we have the staffing requirements for the Mars stand in the file MARS.LDT, our model is then ready to run again. However, this time it will solve for the START values for the Mars hot dog stand. We include commands to do the same for the Saturn location as well. Finally, we have two SET commands to restore the modified parameters.

You can run this command script by issuing the File|Take Commands command in Windows versions of LINGO, or you can use the TAKE command in other versions. Once the command script has been executed, you will find the three solution files: PLUTO.TXT, MARS.TXT, and SATURN.TXT. These files will contain the optimal values for the START attribute for each of the three locations.

 

转载于:https://www.cnblogs.com/iadvance/p/4970219.html

相关文章:

  • c++ 复数类
  • 软件项目发展历史人月神话这本书好
  • Linux -- ubuntu下安装程序的三种方法
  • iOS 利用UIWebView与JavaScript交互的最简单办法(本人已验证可行)
  • 2015-10-14 晴 tcp/ip
  • 00.Python manage.py shell和 Python的分析
  • Visifire实现统计图
  • SecureCRT系列:生成公私钥
  • 技巧之:恢复linux被误删文件(方案有3)
  • 非法词判断
  • 教你爱上Blocks(闭包)
  • 【python游戏编程之旅】第四篇---pygame中加载位图与常用的数学函数。
  • 导出excel
  • Oracle坑爹入门踩坑篇
  • GPU大百科全书索引(有助于理解openGL工作流程)
  • Google 是如何开发 Web 框架的
  • ➹使用webpack配置多页面应用(MPA)
  • 345-反转字符串中的元音字母
  • java取消线程实例
  • Java知识点总结(JDBC-连接步骤及CRUD)
  • JS创建对象模式及其对象原型链探究(一):Object模式
  • magento2项目上线注意事项
  • MaxCompute访问TableStore(OTS) 数据
  • PHP 使用 Swoole - TaskWorker 实现异步操作 Mysql
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • 闭包,sync使用细节
  • 目录与文件属性:编写ls
  • 入门到放弃node系列之Hello Word篇
  • 使用API自动生成工具优化前端工作流
  • 通过来模仿稀土掘金个人页面的布局来学习使用CoordinatorLayout
  • 运行时添加log4j2的appender
  • kubernetes资源对象--ingress
  • #NOIP 2014# day.1 T2 联合权值
  • $分析了六十多年间100万字的政府工作报告,我看到了这样的变迁
  • (9)目标检测_SSD的原理
  • (八)c52学习之旅-中断实验
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (分布式缓存)Redis分片集群
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (强烈推荐)移动端音视频从零到上手(上)
  • (十一)JAVA springboot ssm b2b2c多用户商城系统源码:服务网关Zuul高级篇
  • (轉貼) 2008 Altera 亞洲創新大賽 台灣學生成果傲視全球 [照片花絮] (SOC) (News)
  • .net core 6 集成和使用 mongodb
  • .NET MVC之AOP
  • .Net 知识杂记
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .NET程序员迈向卓越的必由之路
  • .NET连接数据库方式
  • .NET实现之(自动更新)
  • .NET中winform传递参数至Url并获得返回值或文件
  • .Net转前端开发-启航篇,如何定制博客园主题
  • @ModelAttribute注解使用
  • @开发者,一文搞懂什么是 C# 计时器!
  • [Angularjs]ng-select和ng-options
  • [ARC066F]Contest with Drinks Hard