我正在尝试使用NetLogo lpsolve扩展进行线性编程。
从下面的代码中可以看到: -该扩展通过提供变量数来工作(在这种情况下为2) -成本符号写为[coeff.x1 coeff.x2右侧符号],其中符号编码为1、2或3。 -最大化或最小化的函数是[coeff.x1 coeff.x2]
比方说,我想在第一个约束中用一个由Turtles-own调用的变量来构造一个类型化的数字,以便每只海龟都能进行自己的优化。在这里,您可以获得代码的正常功能版本。
extensions [ lpsolver ]
turtles-own [ output x1 x2 ]
to setup
clear-all
create-turtles 2 [ setxy random-xcor random-ycor ]
end
to go
ask turtles [
let numvar 2
let con [
[ 1 1 1 600000 ] ; first constraint. Typing numbers, it works
[ -2 1 2 0 ]
[ 0 1 2 150000 ]
]
let obj [ 1 0.9 ]
let bins [ 1 1 ]
let results (lpsolver:max numvar con obj bins)
set output first results ; these 4 lines are
let results2 but-first results ; just to store the
set x1 first results2 ; results in the
set x2 last results2 ; turtles-own variables
]
end
这是当我尝试用乌龟拥有的变量替换600000的时候。
extensions [ lpsolver ]
turtles-own [ try output x1 x2 ]
to setup
clear-all
create-turtles 2 [ setxy random-xcor random-ycor ]
ask turtles [ set try 600000 ]
end
to go
ask turtles [
let numvar 2
let con [
[ 1 1 1 try ] ; now I get the "expected a constant error"
[ -2 1 2 0 ]
[ 0 1 2 150000 ]
]
let obj [ 1 0.9 ]
let bins [ 1 1 ]
let results (lpsolver:max numvar con obj bins)
set output first results ; these 4 lines are
let results2 but-first results ; just to store the
set x1 first results2 ; results in the
set x2 last results2 ; turtles-own variables
]
end
我知道NetLogo在尝试为它提供一个变量(由Turtle拥有)时要求我提供一个常量,因此,由于我对NetLogo和任何编程语言都不熟悉,因此我尝试了所有方法:方括号,在过程中或外部创建列表,然后尝试将这些列表放置在严格但始终相同的错误中。 唯一的区别是当我尝试使用倒逗号时,例如“尝试”。在这种情况下,“尝试”变为橙色(在《 NetLogo编程指南》中,常量为橙色),当我尝试从“代码”选项卡转到“接口”选项卡时,没有立即出现错误。 但是,当我尝试单击GO时,收到了大错误消息。我猜是 因为“ try”是一个字符串,但是我真的不知道。 如果需要,我将完整的错误消息放在最后。
我该怎么办? 预先感谢!
NetLogo is unable to supply you with more details about this error. Please report the problem
at https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the
contents of this window into your report.
java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\NetLogo 5.3.1\lpsolve55j.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1904)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at lpsolve.LpSolve.<clinit>(LpSolve.java:275)
at lp.report(lp.java:63)
at org.nlogo.prim._externreport.report(_externreport.java:50)
at org.nlogo.prim._let.perform(_let.java:28)
at org.nlogo.nvm.Context.runExclusive(Context.java:119)
at org.nlogo.nvm.ExclusiveJob.run(ExclusiveJob.java:57)
at org.nlogo.nvm.Context.runExclusiveJob(Context.java:162)
at org.nlogo.prim._asm_procedurego_ask_0.perform(:1)
at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)
at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)
at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)
at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at scala.util.control.Exception$Catch.apply(Exception.scala:88)
at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)
at org.nlogo.job.JobThread.run(JobThread.scala:75)
NetLogo 5.3.1
main: org.nlogo.app.AppFrame
thread: AWT-EventQueue-0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_74 (Oracle Corporation; 1.8.0_74-b02)
operating system: Windows 10 10.0 (amd64 processor)
Scala version 2.9.2
JOGL: (3D View not initialized)
OpenGL Graphics: (3D View not initialized)
model: Untitled
09:56:42.291 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
09:56:42.245 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:42.212 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
09:56:42.045 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:41.845 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:41.644 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:41.443 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:41.242 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:41.041 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
09:56:40.841 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0