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.

时间: 2024-08-08 01:28:44

Lingo中命令脚本文件使用范例的相关文章

如何在ChemScript中创建脚本文件

ChemScript是一个化学信息学软件开发工具包(SDK),它包含的编程算法在珀金埃尔默产品中较为常见.本文将讲解如何在ChemBioOffice中的ChemScript申请创建自己的脚本文件. ChemScript的所有脚本文件范例都可以在Python和C#/.NET中获取.如果你熟悉这些语言,你会发现这些脚本很容易理解.但是如果你刚刚接触C#/.NET或Python,我们建议你参考相关的网站和书籍.ChemScript在Python和C#/.NET都可用,而在本教程中我们将使用Python

【Android】使用persist属性来调用脚本文件

Android系统中有许多属性,属性由两个部分组成:name & value,可以使用这些属性来记录系统设置或进程之间的信息交换.Android系统在启动过程时会按序从以下几个文件中加载系统属性: 1./default.prop 2./system/build.prop 3./system/default.prop 4./data/local.prop 5./data/property/* 属性会按照以上文件的顺序进行加载,并且后加载的属性值会更新原先的属性值.在系统重启后,有的属性会消失,但可

配置文件和脚本文件区别

问:像/etc/profile./etc/init.d/rcS等都是脚本文件吗?能不能说明一下脚本文件究竟是什么,用什么作用?谢谢!! 答:你说的这些应该算配置文件,脚本文件一般是可执行的文本格式的文件,反正我是这么认为的,例如linux中可执行的shell脚本就属于脚本文件 追问: 但是觉得像profile和rcS等文件中的内容和可执行脚本文件内容格式差不多啊,那它们又有什么关系呢 追答: 配置文件就是系统,用户等运行程序时依赖的东西,例如可以在profile中配置一些环境变量,快捷操作命令等

mysql中如何在命令行中,执行一个SQL脚本文件?

需求描述: 在mysql数据库的使用中,有的时候,需要直接在shell的命令行中,执行某个SQL脚本文件, 比如,要初始化数据库,创建特定的存储过程,创建表等操作,这里进行一个基本的测试. 一般情况,mysql都是以交互式的方式登录,执行SQL语句的.这里要做的就是将SQL放在一个文件里,让mysql 客户端程序来执行. 操作过程: 1.创建一个SQL脚本的文本文件,里面放想要执行的SQL语句 use test01 select count(*) from ts051; 备注:SQL脚本的文件名

007.链接器命令脚本LD文件教程(1)

开发人员如何指定一个二进制镜像文件的内部布局呢?可以传递给链接器一个链接描述文件,也成为链接器命令脚本.可以将这个特殊的文件看做一份构造二进制可执行镜像的"配方".下面代码中显示了U-Boot引导加载程序使用的链接器描述文件的部分内容. 该脚本从这里开始定义了二进制ELF镜像的输出段.它指示链接器将名为.resetvec的代码段放置在数据镜像的固定地址处,即地址0xFFFFFFFC.此外,它还指定这个段的剩余部分全部填充为1(0xffff).这是因为一个闪存的存储阵列在被擦除后内容全部

创建包含sql命令的sql脚本文件

sql脚本是包含一到多个sql命令的sql语句,我们可以将这些sql脚本放在一个文本文件中(我们称之为“sql脚本文件”),然后通过相关的命令执行这个sql脚本文件.基本步骤如下: 1.创建包含sql命令的sql脚本文件 文件中包含一些列的sql语句,每条语句最后以;结尾,文件内容示例如下: --创建表,使用“--”进行注释 create table 表名称 (                      Guid Varchar(38) not null primary key,     Tit

技术分享:如何在PowerShell脚本中嵌入EXE文件

我在尝试解决一个问题,即在客户端攻击中只使用纯 PowerShell 脚本作为攻击负荷.使用 PowerShell 运行恶意代码具有很多优点,包括: 1.无需在目标上安装其他任何东西. 2.强大的引擎(例如可以直接调用 .NET 代码). 3.可以使用 base64 编码命令来混淆恶意命令,使恶意命令变的不容易被发现.这同样也是一种可以避免使用特殊字符的方法,尤其是在一个涉及多个步骤需要分离不同攻击负荷的高级攻击中. 4.可以使用Invoke-Expression将字符串解释为 Powershe

MySQL执行外部sql脚本文件命令报错:unknown command '\'

由于编码不一致导致的 虽然大部分导出是没有问题的 但是数据表中存储包含一些脚本(富文本内容)会出现该问题,强制指定编码即可解决. mysql导入时指定编码: mysql -u root -p --default-character-set=utf8 或者在导出时后显式指定编码就不存在这个问题了: mysqldump -uroot -p --default-character-set=utf8 mydb > E://xxxx.sql MySQL执行外部sql脚本文件命令报错:unknown com

Jmeter 非 GUI 命令行执行脚本文件

介绍 进行性能测试时,Jmeter 官方文档声明是不建议在 GUI 执行的,此时需要用到命令行. 第一步:环境配置 把 Jmeter安装目录\bin 添加到 系统环境变量path 第二步:命令参数 -n    命令行模式-t 脚本路径-l 测试结果路径(jtl 或者 csv)-j 日志路径-r 分布式执行-R   远程服务器列表-g    生成测试报表-e       设置测试完成后生成测试报表-o       指定测试报表生成文件夹-H      代理服务器IP-P      代理服务器端口