linear programming
ChrLie
http://en.wikipedia.org/wiki/Linear_programming
There is code out there:
http://lpsolve.sourceforge.net/5.5/
and I wonder if there were already attempts to make use of that for Igor and if not what would it take to do it?
Cheers
C
The link you give is to code licensed under LGPL. Our understanding of this license (which is difficult to understand, and causes long threads on any developer forum where the topic comes up) is that we can use such code, but only with some difficulty. Another option, since you don't have the restrictions resulting from publishing a for-profit application, is to write an XOP that wraps up the API in that library.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 17, 2013 at 08:52 am - Permalink
I somehow feared that answer because currently writing an XOP is beyond my skills (I never looked into that and I don't have any experience in C). On the other hand, in my case the number of calls to lp_solve won't be excessive and a work-around for me could be to use Igor to write an input file which can then be processed simply from the command line of the operating system (on Mac in my case). Is there any way of executing a command from the system terminal via Igor and read out whatever lp_solve puts out? I guess that is in a very simplified manner what an XOP does, but would that be feasible?
April 17, 2013 at 01:05 pm - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 17, 2013 at 02:23 pm - Permalink
* create a shell script that will run what you need when given two inputs, the input file and the output file
* put that shell script in your $PATH
* call that shell script from Igor using ExecuteScript
* wait for the return from the ExecuteScript command
* read the output file from Igor
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
April 17, 2013 at 03:03 pm - Permalink
It seems to use the MIT license.
April 17, 2013 at 11:53 pm - Permalink
I have not done this with AppleScript, but using Igor's ExecuteScriptText to run a Windows DOS BAT file. Igor was used to create the input file, call the BAT file (which ran a FORTRAN executable), wait for output file read access, read, analyze, and display the results. A bit kludgy, but should work with any executable whose input and output file formats are known.
April 18, 2013 at 07:08 am - Permalink
string dstr
string exStr, uStr
sprintf uStr, "ls -al \'%s\'" dstr
sprintf exStr, "do shell script \"%s\"" uStr
ExecuteScriptText exStr
return S_value
end
print DirList("/Users/jjw") --> prints directory listing
Suppose the shell level command in your $PATH is lpsolver with flags -r (recursive). You want to run lpsolver on file /Users/jjw/Documents/Data Files/April 23, 2012/first set/run002.dat. You want the output in the same directory as lp_run002.dat. Here is an example off the top of my head that should work.
string iPath, iFile, flags
string iStr, oStr, exStr, uStr
sprintf iStr, "\'%s/%s\'" iPath,iFile // define the input file path
sprintf oStr, "\'%s/lp_%s\'" iPath,iFile // define the output file path
sprintf uStr, "lpsolver -%s \'%s\' \'%s\'", flags, iStr, oStr // generate the shell script command
sprintf exStr, "do shell script \"%s\"" uStr // generate the ExecuteScriptText command
ExecuteScriptText exStr
return S_value
end
MyLPSolver("/Users/jjw/Documents/Data Files/April 23, 2012/first set","run002.dat","r")
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
April 18, 2013 at 08:05 am - Permalink
John, would be great if linear programming and even a solver for non-linear constrained optimisation problems could be added in the future but I understand version 7 has priority now.
Thanks everyone!
C
April 18, 2013 at 08:15 am - Permalink
MMmmm... that looks interesting. The list of features includes "Easy to use graphical interface (GUI)". We would need, of course, to extract just the analysis code to use in Igor.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 18, 2013 at 09:17 am - Permalink
wave gg, AA, bb
// minimises sum { x[i] * gg[i] } by solving for x[i]
// subject to the contraint AA[i][j] * x[i] = bb[j]
//****************
// (1) write input file
//****************
variable IgorIn
string fileName = "IgorModel.lp" // fixed input file name for shell script (see below)
NewPath/Q/O SolverPath, "Macintosh HD:Users:Christian_At_Work:DropBox:Igor:lp_solver" // path to lp_solve unix executable folder
variable i, j
variable numVar = numpnts(gg)
Open/Z/P=SolverPath IgorIn as fileName
fprintf IgorIn, "min: "
// write objective function
for (i=0; i<numVar; i+=1)
fprintf IgorIn, num2str(gg[i]) + "x"+num2str(i) + " "
endfor
fprintf IgorIn, ";\r"
//write contraints
for (j=0; j<Dimsize(AA, 1); j+=1)
for (i=0; i<DimSize(AA, 0); i+=1)
fprintf IgorIn, num2str(AA[i][j]) + "x"+num2str(i)
if (i < DimSize(AA, 1) )
fprintf IgorIn, " + "
endif
endfor
fprintf IgorIn, " = " + num2str(bb[j]) + ";\r"
endfor
Close IgorIn
//************************************************************************************
// (2) run pre-defined unix shell script (here lpsolve.sh) using ExecuteScriptTest; returns lp_solve output in S_value
//************************************************************************************
string uCmd = "lpsolve.sh"
string cmd
sprintf cmd, "do shell script \"%s\"", uCmd
ExecuteScriptText cmd
//Print S_value
//******************************************
// (3) analyse S_value and writes results to W_LPsolved
//******************************************
Make/O/D/N=(numVar) W_LPsolved
string buffer
buffer = Replacestring("\r", S_value, "") // get rid of carriage return
buffer = Replacestring(" ", buffer, "") // collapse white space
for (i=0; i<numVar; i+=1) // format string such that it is analysable using NumberByKey
buffer = Replacestring( "x" + num2str(i) , buffer, ";x" + num2str(i) + "=")
endfor
for (i=0; i<numVar; i+=1) // extract result values and write to W_lpsolved
W_LPsolved[i] = NumberByKey("x"+num2str(i), buffer, "=", ";")
endfor
end
An input file looks like, e.g.
1x0 + 1x1 + 0x2 = 0.4;
1x0 + 0x1 + 1x2 = 0.1;
and S_value:
Value of objective function: -0.06350000
Actual values of the variables:
x0 0.1
x1 0.3
x2 0"
The bottleneck here is obviously the writing-to-disk part.
April 19, 2013 at 02:12 am - Permalink