Alessandro, If you look here:
http://en.wikibooks.org/wiki/GLPK/Unix_Batch_Execution at script tst2a, you'll see an example of generating MathProg data files in a *nix command line environment which should be pretty much all you need. It's much less work than writing a custom program using the library calls. It also makes modifying the model much easier. If you need to pull the data out of something messy send me a sample. awk is really good for tasks such as merging data from several sources or parsing complex formats. Have Fun! Reg --- On Mon, 1/14/13, Alessandro Saccoia <[email protected]> wrote: > From: Alessandro Saccoia <[email protected]> > Subject: Re: [Help-glpk] Problem with absolute value > To: "Jeffrey Kantor" <[email protected]> > Cc: "[email protected]" <[email protected]> > Date: Monday, January 14, 2013, 6:17 AM > Hi Jeff, > that works wonders! Now I would just like to find a way to > use the library instead of the executable, and insert all > this information programmatically. In the glpk docs it seems > that it's up to me to introduce all the variables and create > the A matrix, but from another answer I got in pvt it looks > like I can use this syntax and have the library do the > necessary calculations. > If I can't avoid reading the model from file, I would at > least like to be able to provide the data at runtime. Thanks > for your time! > Alessandro > > On Jan 14, 2013, at 1:04 PM, Jeffrey Kantor <[email protected]> > wrote: > > > Hi Alessandro, > > > > I don't exactly the geometry, but here's a MathProg > model for your problem. If you want to try this out, cut and > paste it into the web page at http://www3.nd.edu/~jeff/mathprog/mathprog.html > > > > Jeff > > > > > > set N := 0..3; > > param q{N}; > > param r{N}; > > > > param a := 0.95; > > param b := 1.05; > > > > var z{N} >= 0; > > var s{N}; > > > > s.t. c1 {n in 0..3}: z[n] >= r[n] - s[n]; > > s.t. c2 {n in 0..3}: z[n] >= s[n] - r[n]; > > s.t. c3 {n in 0..2}: s[n+1] - s[n] >= > a*(q[n+1]-q[n]); > > s.t. c4 {n in 0..2}: s[n+1] - s[n] <= > b*(q[n+1]-q[n]); > > > > minimize obj: sum{n in N} z[n]; > > solve; > > > > data; > > > > param q := > > 0 3 > > 1 5 > > 2 8 > > 3 12 ; > > > > param r := > > 0 2 > > 1 5 > > 2 7 > > 3 11 ; > > > > end; _______________________________________________ Help-glpk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-glpk
