ojalgo-user Mailing List for oj! Algorithms (Page 19)
Mathematics, linear algebra and optimisation
Brought to you by:
apete
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
(14) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2005 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(3) |
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
(5) |
Sep
|
Oct
(3) |
Nov
(4) |
Dec
(2) |
2007 |
Jan
(8) |
Feb
(1) |
Mar
(2) |
Apr
(11) |
May
(6) |
Jun
|
Jul
(10) |
Aug
(2) |
Sep
|
Oct
(4) |
Nov
|
Dec
(11) |
2008 |
Jan
(22) |
Feb
(4) |
Mar
(2) |
Apr
(4) |
May
(2) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(6) |
Nov
(17) |
Dec
(5) |
2009 |
Jan
(15) |
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(4) |
Jun
(5) |
Jul
(9) |
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(14) |
Dec
|
2010 |
Jan
(3) |
Feb
(5) |
Mar
(2) |
Apr
(19) |
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
(5) |
Nov
(3) |
Dec
|
2011 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(10) |
May
(1) |
Jun
(15) |
Jul
(1) |
Aug
|
Sep
|
Oct
(13) |
Nov
(9) |
Dec
(11) |
2012 |
Jan
|
Feb
(1) |
Mar
(9) |
Apr
(23) |
May
(16) |
Jun
(9) |
Jul
(13) |
Aug
|
Sep
(4) |
Oct
(1) |
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
(12) |
Mar
(7) |
Apr
(24) |
May
|
Jun
(7) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(16) |
Nov
(7) |
Dec
(3) |
2014 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(1) |
Oct
(2) |
Nov
(6) |
Dec
(2) |
2015 |
Jan
(11) |
Feb
(10) |
Mar
(1) |
Apr
(9) |
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
(6) |
Oct
(3) |
Nov
(15) |
Dec
(4) |
2016 |
Jan
(6) |
Feb
|
Mar
(18) |
Apr
(5) |
May
(9) |
Jun
(3) |
Jul
(5) |
Aug
(2) |
Sep
(5) |
Oct
(2) |
Nov
|
Dec
(5) |
2017 |
Jan
(4) |
Feb
(3) |
Mar
|
Apr
|
May
(12) |
Jun
(1) |
Jul
(4) |
Aug
|
Sep
(3) |
Oct
(1) |
Nov
|
Dec
(1) |
2018 |
Jan
(5) |
Feb
|
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
|
Jul
(4) |
Aug
(1) |
Sep
(8) |
Oct
|
Nov
|
Dec
(1) |
2019 |
Jan
|
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Harsha N. <har...@ya...> - 2010-11-15 14:45:29
|
Hi - I just checked out code from CVS. There are 2 main problems and the code does not compile. org.ojalgo.random.process.MultidemsionalProcess is not checked in and is used in AbstractSimulator in org.ojalgo.randon.process.simulator This leads to 6 compilation errors. Line 56 in AbstractSimulator also has an error "getValue is undefined for the type P". I browsed CVS online as well and this class seems to be missing. Could you please fix these? Also, which package/class has unit tests/junits/examples that we could try out to begin with Thanks Harsha |
From: Anders P. <an...@op...> - 2010-10-07 20:48:49
|
ojAlgo only supports BigDecimal, ComplexNumber and double matrices. It would be very easy to extend ojAlgo to also support float and/or some other Number subclass, but I have no plans to do so. The recommendation/intention is that you should work either with BasicMatrix or MatrixStore/PhysicalStore - don't mix. If you want to create a BasicMatrix with double elements you do this: BasicMatrix b = PrimitiveMatrix.FACTORY.makeEye(4,4); Where do you get an "error" when you use Float? If you want to work with small matrices (3x3 and 4x4) with float elements maybe you should look at javax.vecmath. https://vecmath.dev.java.net/ ojAlgo is best suited for larger matrices. /Anders On 7 okt 2010, at 21.55, Birgit Doelle wrote: > Hi to all ojaglo-user! > My problem: > I want to do high performance calculations with matrices. For precision is float enough. I found a way to create a double-matrix. > > "MatrixStore<Double> a = PrimitiveDenseStore.FACTORY.makeEye(4,4); " > "BasicMatrix b = new PrimitiveMatrix(a);" > > But how can I create a float-matrix? I know, that there are many factories, which expect a type of Number, like double or float. But if I set Float, I get only errors. > > Nice would be a short tutorial how to deal with float-matrices in ojaglo. I will need functions like add, mult and invert. And the initialization should be possible with a 2-dimensional-float-array, or something like that. > > Thanks for your help > Birgit > > > > > > Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! > Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02 > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Birgit D. <bir...@we...> - 2010-10-07 19:55:19
|
<body bgcolor="#ffffff" background="https://img.web.de/v/p.gif" class="bgRepeatYes" style="background-repeat: repeat; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-family: verdana,geneva; font-size: 9pt; padding-left: 0px;"><div style="min-height: 200px; background-image: url(https://img.web.de/v/p.gif); background-repeat: repeat; background-color: #ffffff; font-family: verdana,geneva; font-size: 9pt; padding-left: 0px;"><span style="font-size: 9pt;"><span style="font-family: verdana,geneva;"><span style="background-color: transparent;"><span style="color: #000000;"><span style="color: #000000;">Hi to all ojaglo-user!<br />My problem:<br />I want to do high performance calculations with matrices. </span></span></span></span></span> For precision is float enough. I found a way to create a double-matrix. <br /><br />"MatrixStore<Double> a = PrimitiveDenseStore.FACTORY.makeEye(4,4); " <br />"BasicMatrix b = new PrimitiveMatrix(a);"<br /><br />But how can I create a float-matrix? I know, that there are many factories, which expect a type of Number, like double or float. But if I set Float, I get only errors. <br /><br />Nice would be a short tutorial how to deal with float-matrices in ojaglo. I will need functions like add, mult and invert. And the initialization should be possible with a 2-dimensional-float-array, or something like that.<br /><br />Thanks for your help<br />Birgit<br /><br /><br /></div> <br><br><table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#000000"><img src="https://img.web.de/p.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td style="font-family:verdana; font-size:12px; line-height:17px;">Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! <br>Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02</td></tr></table> </body> |
From: David J. <dav...@bu...> - 2010-10-06 21:05:42
|
Fair enough. I think the issue was just that I was trying to configure my problem through QuadraticExpressionModel where it really wasn't necessary, since my equation is in the standard form taken by the builder. Going purely by the builder's configuration methods, my code seems to be functioning: //now minimize (1/2*transpose(alpha)*H*alpha - sum(alpha)) //subject to I*alpha <= C //build singular column vector to multiply by alpha, in order //to represent sum(alpha) double[] tempsing = new double[c]; Arrays.fill(tempsing, 1); JamaMatrix sing = jfac.makeColumn(tempsing); //build AI = I JamaMatrix AI = jfac.makeEye(c, c); //build BI = C double[] BItemp = new double[c]; Arrays.fill(BItemp, C); JamaMatrix BI = jfac.makeColumn(BItemp); //initialize alpha double[] alphatemp = new double[c]; JamaMatrix alpha = jfac.makeColumn(alphatemp); //Set up the minimizer final Variable[] vars = new Variable[0]; final QuadraticExpressionsModel qem = new QuadraticExpressionsModel(vars); qem.setMinimisation(true); final QuadraticSolver.Builder build = new QuadraticSolver.Builder(qem); build.objective(H, sing); build.inequalities(AI, BI); build.setX(alpha); QuadraticSolver solver = build.build(); OptimisationSolver.Result res = solver.solve(); On Wed, Oct 6, 2010 at 4:05 PM, Anders Peterson <an...@op...>wrote: > The code you've written declares an optimisation problem with 2 variables, > but the variable H is not part of the objective function, not part of any > expression and not constrained in any way. > > Actually I think you ask too many things at the same time; how can you not > know if alpha and H should be "listed" as variables or not? Are they > variables? > > You make something (a single variable, or a whole expression) part of the > objective function by setting its contribution weight. What you set > individual weights to only matters in relation other weights. > > You constrain something (single variable, or whole expressions) by setting > lower and/or upper limits. > > /Anders > > > On 6 okt 2010, at 01.17, David Johnson wrote: > > > Hi, I'm new to ojalgo, and trying to work out the exact syntax needed to > configure the quadratic solver. > > > > Specifically, I'm trying to solve a standard quadratic minimization > problem: min(1/2*transpose(alpha)*H*alpha - sum(alpha)), given 0 <= alphai > <= C (where C is a constant), for each element in alpha. Alpha will be > initialized to 0s (or uninitialized, if no initial input is needed) and H to > a given input matrix. I'm unclear on exactly what I need to configure in > the QuadraticExpressionsModel versus what is handled by the builder. I also > can't seem to find a current example of how to configure an expression-based > model (except for the one in MarkowitzModel, which helped, but didn't > entirely clarify the logic). > > > > My current (very rough) code skeleton looks like this: > > > > final Variable[] vars = new Variable[2]; > > vars[0] = new Variable("alpha"); > > vars[0].setLowerLimit(new BigDecimal(0)); > > vars[0].setUpperLimit(new BigDecimal(C)); > > vars[0].setContributionWeight(BigMath.ONE); > > vars[1] = new Variable("H"); > > > > final QuadraticExpressionsModel qem = new > QuadraticExpressionsModel(vars); > > qem.setMinimisation(true); > > > > final QuadraticSolver.Builder build = new > QuadraticSolver.Builder(qem); > > > > I can't tell if alpha and H should even be listed as variables (as > opposed to expressions), how to associate my input matrices with them if > they should be, and how to describe range limits on alpha if they should > not. I'm also not certain how to define my objective function - is the > basic format handled by the builder, or do I need to describe it in the > model somehow? Should I be using the inequalities(...) and objective(...) > functions in the builder, or defining those via the model? > > > > Also, I know I can represent sum(alpha) in my equation by just setting C > (the vector in the basic equation format, not my constant) to be a singular > 1 vector, but is there any way to ensure that the solver will then treat C > as a constant? > > > > Thanks > > David Johnson > > > ------------------------------------------------------------------------------ > > Beautiful is writing same markup. Internet Explorer 9 supports > > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > > Spend less time writing and rewriting code and more time creating great > > experiences on the web. Be a part of the beta today. > > > http://p.sf.net/sfu/beautyoftheweb_______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > |
From: Anders P. <an...@op...> - 2010-10-06 20:22:46
|
The code you've written declares an optimisation problem with 2 variables, but the variable H is not part of the objective function, not part of any expression and not constrained in any way. Actually I think you ask too many things at the same time; how can you not know if alpha and H should be "listed" as variables or not? Are they variables? You make something (a single variable, or a whole expression) part of the objective function by setting its contribution weight. What you set individual weights to only matters in relation other weights. You constrain something (single variable, or whole expressions) by setting lower and/or upper limits. /Anders On 6 okt 2010, at 01.17, David Johnson wrote: > Hi, I'm new to ojalgo, and trying to work out the exact syntax needed to configure the quadratic solver. > > Specifically, I'm trying to solve a standard quadratic minimization problem: min(1/2*transpose(alpha)*H*alpha - sum(alpha)), given 0 <= alphai <= C (where C is a constant), for each element in alpha. Alpha will be initialized to 0s (or uninitialized, if no initial input is needed) and H to a given input matrix. I'm unclear on exactly what I need to configure in the QuadraticExpressionsModel versus what is handled by the builder. I also can't seem to find a current example of how to configure an expression-based model (except for the one in MarkowitzModel, which helped, but didn't entirely clarify the logic). > > My current (very rough) code skeleton looks like this: > > final Variable[] vars = new Variable[2]; > vars[0] = new Variable("alpha"); > vars[0].setLowerLimit(new BigDecimal(0)); > vars[0].setUpperLimit(new BigDecimal(C)); > vars[0].setContributionWeight(BigMath.ONE); > vars[1] = new Variable("H"); > > final QuadraticExpressionsModel qem = new QuadraticExpressionsModel(vars); > qem.setMinimisation(true); > > final QuadraticSolver.Builder build = new QuadraticSolver.Builder(qem); > > I can't tell if alpha and H should even be listed as variables (as opposed to expressions), how to associate my input matrices with them if they should be, and how to describe range limits on alpha if they should not. I'm also not certain how to define my objective function - is the basic format handled by the builder, or do I need to describe it in the model somehow? Should I be using the inequalities(...) and objective(...) functions in the builder, or defining those via the model? > > Also, I know I can represent sum(alpha) in my equation by just setting C (the vector in the basic equation format, not my constant) to be a singular 1 vector, but is there any way to ensure that the solver will then treat C as a constant? > > Thanks > David Johnson > ------------------------------------------------------------------------------ > Beautiful is writing same markup. Internet Explorer 9 supports > standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. > Spend less time writing and rewriting code and more time creating great > experiences on the web. Be a part of the beta today. > http://p.sf.net/sfu/beautyoftheweb_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: David J. <dav...@bu...> - 2010-10-05 23:17:18
|
Hi, I'm new to ojalgo, and trying to work out the exact syntax needed to configure the quadratic solver. Specifically, I'm trying to solve a standard quadratic minimization problem: min(1/2*transpose(alpha)*H*alpha - sum(alpha)), given 0 <= alphai <= C (where C is a constant), for each element in alpha. Alpha will be initialized to 0s (or uninitialized, if no initial input is needed) and H to a given input matrix. I'm unclear on exactly what I need to configure in the QuadraticExpressionsModel versus what is handled by the builder. I also can't seem to find a current example of how to configure an expression-based model (except for the one in MarkowitzModel, which helped, but didn't entirely clarify the logic). My current (very rough) code skeleton looks like this: final Variable[] vars = new Variable[2]; vars[0] = new Variable("alpha"); vars[0].setLowerLimit(new BigDecimal(0)); vars[0].setUpperLimit(new BigDecimal(C)); vars[0].setContributionWeight(BigMath.ONE); vars[1] = new Variable("H"); final QuadraticExpressionsModel qem = new QuadraticExpressionsModel(vars); qem.setMinimisation(true); final QuadraticSolver.Builder build = new QuadraticSolver.Builder(qem); I can't tell if alpha and H should even be listed as variables (as opposed to expressions), how to associate my input matrices with them if they should be, and how to describe range limits on alpha if they should not. I'm also not certain how to define my objective function - is the basic format handled by the builder, or do I need to describe it in the model somehow? Should I be using the inequalities(...) and objective(...) functions in the builder, or defining those via the model? Also, I know I can represent sum(alpha) in my equation by just setting C (the vector in the basic equation format, not my constant) to be a singular 1 vector, but is there any way to ensure that the solver will then treat C as a constant? Thanks David Johnson |
From: Anders P. <an...@op...> - 2010-08-17 20:58:04
|
I recommend you start building your optimization models using QuadraticExpressionsModel. If you absolutely want to construct your own matrices then perhaps a PrimitiveDenseStore could be a suitable MatrixStore implementation to use. /Anders On 17 aug 2010, at 02.48, Menglin Liu wrote: > Hi there, > > sorry to bother. > > i'm new to Ojalgo. I want to use it to solve quadratic optimization problem. > > In QuadraticSolver.class, the method public Builder(final MatrixStore<Double> Q, final MatrixStore<Double> C) shows we need to construct the MatrixStore for Q and C. But in MaxtrixStore.class, it says "This interface does not define any methods that require implementations > to alter the matrix. Either the methods return matrix elements, some meta data or produce new instances." > > I'm asking how can i construct the MatrixStore from a series of data? Could anyone send me a little piece of code about this? > > Thank you very much! > > Menglin > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Menglin L. <sup...@li...> - 2010-08-17 00:48:48
|
Hi there, sorry to bother. i'm new to Ojalgo. I want to use it to solve quadratic optimization problem. In QuadraticSolver.class, the method public Builder(final MatrixStore<Double> Q, final MatrixStore<Double> C) shows we need to construct the MatrixStore for Q and C. But in MaxtrixStore.class, it says "This interface does not define any methods that require implementations to alter the matrix. Either the methods return matrix elements, some meta data or produce new instances." I'm asking how can i construct the MatrixStore from a series of data? Could anyone send me a little piece of code about this? Thank you very much! Menglin |
From: Anders P. <an...@op...> - 2010-04-25 19:26:38
|
ok, but I think I'll have to call it makeBinary(...) /Anders On 25 apr 2010, at 21.01, Luke Lindsay wrote: > On 23 April 2010 22:57, Anders Peterson <an...@op...> wrote: >> All your test cases (1 + 5) work now. >> >> Fixed a bug with the IntegerSolver related to determining if a branch-solution is an integer solution or not. >> Fixed a bug with the ExpressionsBasedModel (that only affected integer models) that resulted in all models being treated as minimization models. >> Changed/improved the LinearSolver. It generally seems better now, but there's actually a couple of unit tests that used to work that now fail. Not finished with this yet. >> >> /Anders >> > Thanks Anders. The new code works correctly with all cases I've tried so far. > > I was wondering if it would be possible to add a static factory method > for creating binary variables since it would make my code more > readable, e.g. > > public static Variable binary(final String aName){ > return new Variable(aName).lower(ZERO).upper(ONE).integer(true); > } > > > Best, > > Luke > > ------------------------------------------------------------------------------ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Luke L. <luk...@gm...> - 2010-04-25 19:01:16
|
On 23 April 2010 22:57, Anders Peterson <an...@op...> wrote: > All your test cases (1 + 5) work now. > > Fixed a bug with the IntegerSolver related to determining if a branch-solution is an integer solution or not. > Fixed a bug with the ExpressionsBasedModel (that only affected integer models) that resulted in all models being treated as minimization models. > Changed/improved the LinearSolver. It generally seems better now, but there's actually a couple of unit tests that used to work that now fail. Not finished with this yet. > > /Anders > Thanks Anders. The new code works correctly with all cases I've tried so far. I was wondering if it would be possible to add a static factory method for creating binary variables since it would make my code more readable, e.g. public static Variable binary(final String aName){ return new Variable(aName).lower(ZERO).upper(ONE).integer(true); } Best, Luke |
From: Anders P. <an...@op...> - 2010-04-23 20:57:33
|
All your test cases (1 + 5) work now. Fixed a bug with the IntegerSolver related to determining if a branch-solution is an integer solution or not. Fixed a bug with the ExpressionsBasedModel (that only affected integer models) that resulted in all models being treated as minimization models. Changed/improved the LinearSolver. It generally seems better now, but there's actually a couple of unit tests that used to work that now fail. Not finished with this yet. /Anders On 22 apr 2010, at 18.55, Luke Lindsay wrote: > On 19 April 2010 08:45, Anders Peterson <an...@op...> wrote: >> Not finished fixing yet... >> >> Yes, please write a junit test. Most likely the problem is actually with the LP (sub) solver, and not the MIP (master) solver. My guess is that there is one particular MIP-branch that is incorrectly reported as solved by the LP solver. (That was the problem last time.) Write a junit test for that particular LP problem as well. >> >> If you also check out theTestProj module from CVS you'll find your problem/case in >> >> org.ojalgo.optimisation.integer.ReportedProblems >> >> and >> >> org.ojalgo.optimisation.linear.ReportedProblems >> >> >> Don't forget to set GenericSolver.DEBUG=true when you debug. >> >> /Anders >> > Here is a junit test. Currently, tests 1 and 4 fail and the others > pass. I don't understand what is causing the problem, but in the test > cases that fail, the binary variables are being set to values other > than 0 or 1. > > Luke > > > .......................................................................................................... > package org.ojalgo.optimisation.integer; > > import static org.ojalgo.constant.BigMath.ONE; > import static org.ojalgo.constant.BigMath.ZERO; > > import java.math.BigDecimal; > import java.util.ArrayList; > > import junit.framework.TestCase; > > import org.ojalgo.optimisation.Expression; > import org.ojalgo.optimisation.Variable; > import org.ojalgo.optimisation.linear.LinearExpressionsModel; > > public class KnapsackTest extends TestCase { > > LinearExpressionsModel model; > > void assertOne(Variable v){ > assertEquals(new BigDecimal("1.0"), v.getValue()); > } > > void assertZero(Variable v){ > assertEquals(new BigDecimal("0.0"), v.getValue()); > } > > public void testVaryingMaxWeight0(){ > model = new KnapsackProblemBuilder(3d).addItem(20, 2).addItem(30, 4).build(); > model.maximise(); > //Expected: just first item > assertOne( model.getVariables()[0]); > assertZero( model.getVariables()[1]); > > } > > public void testVaryingMaxWeight1(){ > model = new KnapsackProblemBuilder(1.1d).addItem(20, 2).addItem(30, > 4).build(); > model.maximise(); > //Expected: nothing > assertZero( model.getVariables()[0]); > assertZero( model.getVariables()[1]); > } > > public void testVaryingMaxWeight2(){ > model = new KnapsackProblemBuilder(0d).addItem(20, 2).addItem(30, 4).build(); > model.maximise(); > //Expected: nothing > assertZero( model.getVariables()[0]); > assertZero( model.getVariables()[1]); > } > > public void testVaryingMaxWeight3(){ > model = new KnapsackProblemBuilder(10d).addItem(20, 2).addItem(30, 4).build(); > model.maximise(); > //Expected: both > assertOne( model.getVariables()[0]); > assertOne( model.getVariables()[1]); > } > > public void testVaryingMaxWeight4(){ > model = new KnapsackProblemBuilder(5d).addItem(20, 2).addItem(30, 4).build(); > model.maximise(); > //Expected: just second item > assertOne( model.getVariables()[1]); > assertZero( model.getVariables()[0]); > > } > > static class KnapsackProblemBuilder { > > final BigDecimal maxWeight; > > final ArrayList<KnapsackItem> items = new ArrayList<KnapsackItem>(); > > KnapsackProblemBuilder(double maxWeight){ > this.maxWeight = new BigDecimal(maxWeight); > } > > KnapsackProblemBuilder addItem(int weight, int value){ > items.add(new KnapsackItem(weight, value)); > return this; > } > > LinearExpressionsModel build() { > > final Variable[] tmpVariables = new Variable[items.size()]; > for (int i = 0; i < tmpVariables.length; i++) { > tmpVariables[i] = new Variable("Var" + String.valueOf(i)); > tmpVariables[i].lower(ZERO).upper(ONE).weight(items.get(i).value).integer(true); > } > > final LinearExpressionsModel retVal = new > LinearExpressionsModel(tmpVariables); > final Expression tmpTotalWeightExpr = > retVal.addEmptyLinearExpression("Total Weight"); > for (int i = 0; i < items.size(); i++) { > tmpTotalWeightExpr.setLinearFactor(i, items.get(i).weight); > } > tmpTotalWeightExpr.lower(ZERO).upper(maxWeight); > > retVal.setMaximisation(true); > > return retVal; > } > > } > > } > > ------------------------------------------------------------------------------ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Luke L. <luk...@gm...> - 2010-04-22 16:55:53
|
On 19 April 2010 08:45, Anders Peterson <an...@op...> wrote: > Not finished fixing yet... > > Yes, please write a junit test. Most likely the problem is actually with the LP (sub) solver, and not the MIP (master) solver. My guess is that there is one particular MIP-branch that is incorrectly reported as solved by the LP solver. (That was the problem last time.) Write a junit test for that particular LP problem as well. > > If you also check out theTestProj module from CVS you'll find your problem/case in > > org.ojalgo.optimisation.integer.ReportedProblems > > and > > org.ojalgo.optimisation.linear.ReportedProblems > > > Don't forget to set GenericSolver.DEBUG=true when you debug. > > /Anders > Here is a junit test. Currently, tests 1 and 4 fail and the others pass. I don't understand what is causing the problem, but in the test cases that fail, the binary variables are being set to values other than 0 or 1. Luke ......................................................................................................... package org.ojalgo.optimisation.integer; import static org.ojalgo.constant.BigMath.ONE; import static org.ojalgo.constant.BigMath.ZERO; import java.math.BigDecimal; import java.util.ArrayList; import junit.framework.TestCase; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.Variable; import org.ojalgo.optimisation.linear.LinearExpressionsModel; public class KnapsackTest extends TestCase { LinearExpressionsModel model; void assertOne(Variable v){ assertEquals(new BigDecimal("1.0"), v.getValue()); } void assertZero(Variable v){ assertEquals(new BigDecimal("0.0"), v.getValue()); } public void testVaryingMaxWeight0(){ model = new KnapsackProblemBuilder(3d).addItem(20, 2).addItem(30, 4).build(); model.maximise(); //Expected: just first item assertOne( model.getVariables()[0]); assertZero( model.getVariables()[1]); } public void testVaryingMaxWeight1(){ model = new KnapsackProblemBuilder(1.1d).addItem(20, 2).addItem(30, 4).build(); model.maximise(); //Expected: nothing assertZero( model.getVariables()[0]); assertZero( model.getVariables()[1]); } public void testVaryingMaxWeight2(){ model = new KnapsackProblemBuilder(0d).addItem(20, 2).addItem(30, 4).build(); model.maximise(); //Expected: nothing assertZero( model.getVariables()[0]); assertZero( model.getVariables()[1]); } public void testVaryingMaxWeight3(){ model = new KnapsackProblemBuilder(10d).addItem(20, 2).addItem(30, 4).build(); model.maximise(); //Expected: both assertOne( model.getVariables()[0]); assertOne( model.getVariables()[1]); } public void testVaryingMaxWeight4(){ model = new KnapsackProblemBuilder(5d).addItem(20, 2).addItem(30, 4).build(); model.maximise(); //Expected: just second item assertOne( model.getVariables()[1]); assertZero( model.getVariables()[0]); } static class KnapsackProblemBuilder { final BigDecimal maxWeight; final ArrayList<KnapsackItem> items = new ArrayList<KnapsackItem>(); KnapsackProblemBuilder(double maxWeight){ this.maxWeight = new BigDecimal(maxWeight); } KnapsackProblemBuilder addItem(int weight, int value){ items.add(new KnapsackItem(weight, value)); return this; } LinearExpressionsModel build() { final Variable[] tmpVariables = new Variable[items.size()]; for (int i = 0; i < tmpVariables.length; i++) { tmpVariables[i] = new Variable("Var" + String.valueOf(i)); tmpVariables[i].lower(ZERO).upper(ONE).weight(items.get(i).value).integer(true); } final LinearExpressionsModel retVal = new LinearExpressionsModel(tmpVariables); final Expression tmpTotalWeightExpr = retVal.addEmptyLinearExpression("Total Weight"); for (int i = 0; i < items.size(); i++) { tmpTotalWeightExpr.setLinearFactor(i, items.get(i).weight); } tmpTotalWeightExpr.lower(ZERO).upper(maxWeight); retVal.setMaximisation(true); return retVal; } } } |
From: Anders P. <an...@op...> - 2010-04-19 06:45:43
|
Not finished fixing yet... Yes, please write a junit test. Most likely the problem is actually with the LP (sub) solver, and not the MIP (master) solver. My guess is that there is one particular MIP-branch that is incorrectly reported as solved by the LP solver. (That was the problem last time.) Write a junit test for that particular LP problem as well. If you also check out theTestProj module from CVS you'll find your problem/case in org.ojalgo.optimisation.integer.ReportedProblems and org.ojalgo.optimisation.linear.ReportedProblems Don't forget to set GenericSolver.DEBUG=true when you debug. /Anders On 18 apr 2010, at 23.16, Luke Lindsay wrote: > On 12 April 2010 20:31, Anders Peterson <an...@op...> wrote: >> Don't think you've done anything wrong. >> >> I've looked briefly at your test case and can already conclude that the IntegerSolver does not work properly for maximization problems (all the test cases are minimization problems). Immediately fixed one part of the problem, but it still doesn't work... >> >> I'll definitely look into this some more, but I'm a little short on time currently. It may take some time. >> >> You can turn on debugging with >> >> GenericSolver.DEBUG = true; >> >> >> Once you've called >> >> model.maximise(); >> >> the problem is already solved, and the solution written back to your variables. >> >> You may simply >> >> System.out.println(model); >> >> go "see" the results. This way you don't get access to the OptimisationState. >> >> >> If you want to solve the problem with explicit access to the Solver and Result you'd do something like this: >> >> model.setMaximisation(true); >> final OptimisationSolver solver = model.getDefaultSolver(); >> final Result result = solver.solve(); >> >> >> /Anders >> >> > Thank you for your reply. > > I have checked out the latest code from CVS. The test case in my > previous email now works as expected. However, when I change the > numbers, I still get some unexpected results. For instance, when I > set my variable maxWeight = 1.1 or maxWeight = 5, the integer > constraints don't hold. I can write a junit test if it would help. > > Best, > > Luke > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Luke L. <luk...@gm...> - 2010-04-18 21:16:55
|
On 12 April 2010 20:31, Anders Peterson <an...@op...> wrote: > Don't think you've done anything wrong. > > I've looked briefly at your test case and can already conclude that the IntegerSolver does not work properly for maximization problems (all the test cases are minimization problems). Immediately fixed one part of the problem, but it still doesn't work... > > I'll definitely look into this some more, but I'm a little short on time currently. It may take some time. > > You can turn on debugging with > > GenericSolver.DEBUG = true; > > > Once you've called > > model.maximise(); > > the problem is already solved, and the solution written back to your variables. > > You may simply > > System.out.println(model); > > go "see" the results. This way you don't get access to the OptimisationState. > > > If you want to solve the problem with explicit access to the Solver and Result you'd do something like this: > > model.setMaximisation(true); > final OptimisationSolver solver = model.getDefaultSolver(); > final Result result = solver.solve(); > > > /Anders > > Thank you for your reply. I have checked out the latest code from CVS. The test case in my previous email now works as expected. However, when I change the numbers, I still get some unexpected results. For instance, when I set my variable maxWeight = 1.1 or maxWeight = 5, the integer constraints don't hold. I can write a junit test if it would help. Best, Luke |
From: Andy T. <A.G...@le...> - 2010-04-15 23:38:30
|
Thanks for the pointers Anders. Indeed ojAlgo is very interesting to me and I think it is complimentary in various ways to things I have been developing, including a calculator for matrices with hundreds of thousands of rows and columns... I have been wanting to find a good reason to develop this further so that the matrix values can be BigDecimal. I will try to use ojAlgo more and learn more about what it has to offer. I will probably be side tracked for a while, but I wanted to reply again and say thanks and encourage you and other ojAlgo developers (assuming there are some) to keep up the work. Best wishes, Andy ________________________________________ From: Anders Peterson [an...@op...] Sent: 15 April 2010 15:07 To: ojAlgo ojAlgo Subject: Re: [ojAlgo-user] Precision I believe that the BigFunction class (itself) is not what could be of most interest to you. Perhaps the fact that ojAlgo contains a complete linear algebra "package" coded with BigDecimal is more interesting. http://ojalgo.org/generated/org/ojalgo/matrix/BigMatrix.html http://ojalgo.org/generated/org/ojalgo/matrix/decomposition/SingularValueDecomposition.html#makeBig() /Anders On 14 apr 2010, at 20.58, Andy Turner wrote: > Thanks Anders :-) > > In some of my code I provide a MathContext for calculations and a MathContext for returns to some methods and use these to guarantee that what is returned is precise to a scale. > > I have a square root function which is like that. I have a use for it in precise distance calculations. > > I was hoping to use other functions from jAlgo like that too, but at least I can use MathContext.DECIMAL128 to improve the precision in some things... > > I'll have a look at the RationalNumber class... > > Bye for now, > > Andy > > > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 14 April 2010 19:36 > To: oja...@li... > Subject: Re: [ojAlgo-user] Precision > > You should look at precision rather than scale. > > If you look at the BigFunction source code you'll se that most of the implementations either delegate to BigDecimal or to PrimitiveFunction. When it delegates to PrimitiveFunction the precision is given by double otherwise MathContext.DECIMAL128 is used. You cannot control this. > > Did you notice the RationalNumber class? > > http://ojalgo.org/generated/org/ojalgo/scalar/RationalNumber.html > > /Anders > > > On 14 apr 2010, at 17.50, Andy Turner wrote: > >> With functions how do I know what precision is returned and can a specific precision be requested? >> >> Running the following code for example shows me that by default rootThousand0 is returned with a scale of 48 where as the rootTwo is returned with a scale of 52. Setting the scale of what is input seems not to have an effect. >> >> BigDecimal rootThousand0 = BigFunction.POW.invoke( >> BigMath.THOUSAND, >> BigMath.HALF); >> System.out.println("" + BigMath.THOUSAND + " precision " + BigMath.THOUSAND.scale()); >> System.out.println("" + BigMath.HALF + " precision " + BigMath.HALF.scale()); >> System.out.println("" + rootThousand0 + " precision " + rootThousand0.scale()); >> System.out.println("Math.pow(1000.0d,0.5d) " + Math.pow(1000.0d,0.5d)); >> >> BigDecimal thousand = BigMath.THOUSAND.setScale(100); >> BigDecimal half = BigMath.HALF.setScale(100); >> BigDecimal rootThousand1 = BigFunction.POW.invoke( >> thousand, >> half); >> System.out.println("" + rootThousand1 + " precision " + rootThousand1.scale()); >> >> BigDecimal rootTwo = BigFunction.POW.invoke( >> BigMath.TWO, >> BigMath.HALF); >> System.out.println("" + rootTwo + " precision " + rootTwo.scale()); >> System.out.println("Math.pow(2.0d,0.5d) " + Math.pow(2.0d,0.5d)); >> >> >> TIA for any help or guidance. >> >> Andy >> http://www.geog.leeds.ac.uk/people/a.turner/ >> >> >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2010-04-15 14:07:51
|
I believe that the BigFunction class (itself) is not what could be of most interest to you. Perhaps the fact that ojAlgo contains a complete linear algebra "package" coded with BigDecimal is more interesting. http://ojalgo.org/generated/org/ojalgo/matrix/BigMatrix.html http://ojalgo.org/generated/org/ojalgo/matrix/decomposition/SingularValueDecomposition.html#makeBig() /Anders On 14 apr 2010, at 20.58, Andy Turner wrote: > Thanks Anders :-) > > In some of my code I provide a MathContext for calculations and a MathContext for returns to some methods and use these to guarantee that what is returned is precise to a scale. > > I have a square root function which is like that. I have a use for it in precise distance calculations. > > I was hoping to use other functions from jAlgo like that too, but at least I can use MathContext.DECIMAL128 to improve the precision in some things... > > I'll have a look at the RationalNumber class... > > Bye for now, > > Andy > > > -----Original Message----- >> From: Anders Peterson [mailto:an...@op...] > Sent: 14 April 2010 19:36 > To: oja...@li... > Subject: Re: [ojAlgo-user] Precision > > You should look at precision rather than scale. > > If you look at the BigFunction source code you'll se that most of the implementations either delegate to BigDecimal or to PrimitiveFunction. When it delegates to PrimitiveFunction the precision is given by double otherwise MathContext.DECIMAL128 is used. You cannot control this. > > Did you notice the RationalNumber class? > > http://ojalgo.org/generated/org/ojalgo/scalar/RationalNumber.html > > /Anders > > > On 14 apr 2010, at 17.50, Andy Turner wrote: > >> With functions how do I know what precision is returned and can a specific precision be requested? >> >> Running the following code for example shows me that by default rootThousand0 is returned with a scale of 48 where as the rootTwo is returned with a scale of 52. Setting the scale of what is input seems not to have an effect. >> >> BigDecimal rootThousand0 = BigFunction.POW.invoke( >> BigMath.THOUSAND, >> BigMath.HALF); >> System.out.println("" + BigMath.THOUSAND + " precision " + BigMath.THOUSAND.scale()); >> System.out.println("" + BigMath.HALF + " precision " + BigMath.HALF.scale()); >> System.out.println("" + rootThousand0 + " precision " + rootThousand0.scale()); >> System.out.println("Math.pow(1000.0d,0.5d) " + Math.pow(1000.0d,0.5d)); >> >> BigDecimal thousand = BigMath.THOUSAND.setScale(100); >> BigDecimal half = BigMath.HALF.setScale(100); >> BigDecimal rootThousand1 = BigFunction.POW.invoke( >> thousand, >> half); >> System.out.println("" + rootThousand1 + " precision " + rootThousand1.scale()); >> >> BigDecimal rootTwo = BigFunction.POW.invoke( >> BigMath.TWO, >> BigMath.HALF); >> System.out.println("" + rootTwo + " precision " + rootTwo.scale()); >> System.out.println("Math.pow(2.0d,0.5d) " + Math.pow(2.0d,0.5d)); >> >> >> TIA for any help or guidance. >> >> Andy >> http://www.geog.leeds.ac.uk/people/a.turner/ >> >> >> >> ------------------------------------------------------------------------------ >> Download Intel® Parallel Studio Eval >> Try the new software tools for yourself. Speed compiling, find bugs >> proactively, and fine-tune applications for parallel performance. >> See why Intel Parallel Studio got high marks during beta. >> http://p.sf.net/sfu/intel-sw-dev >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Andy T. <A.G...@le...> - 2010-04-14 18:59:15
|
Thanks Anders :-) In some of my code I provide a MathContext for calculations and a MathContext for returns to some methods and use these to guarantee that what is returned is precise to a scale. I have a square root function which is like that. I have a use for it in precise distance calculations. I was hoping to use other functions from jAlgo like that too, but at least I can use MathContext.DECIMAL128 to improve the precision in some things... I'll have a look at the RationalNumber class... Bye for now, Andy -----Original Message----- From: Anders Peterson [mailto:an...@op...] Sent: 14 April 2010 19:36 To: oja...@li... Subject: Re: [ojAlgo-user] Precision You should look at precision rather than scale. If you look at the BigFunction source code you'll se that most of the implementations either delegate to BigDecimal or to PrimitiveFunction. When it delegates to PrimitiveFunction the precision is given by double otherwise MathContext.DECIMAL128 is used. You cannot control this. Did you notice the RationalNumber class? http://ojalgo.org/generated/org/ojalgo/scalar/RationalNumber.html /Anders On 14 apr 2010, at 17.50, Andy Turner wrote: > With functions how do I know what precision is returned and can a specific precision be requested? > > Running the following code for example shows me that by default rootThousand0 is returned with a scale of 48 where as the rootTwo is returned with a scale of 52. Setting the scale of what is input seems not to have an effect. > > BigDecimal rootThousand0 = BigFunction.POW.invoke( > BigMath.THOUSAND, > BigMath.HALF); > System.out.println("" + BigMath.THOUSAND + " precision " + BigMath.THOUSAND.scale()); > System.out.println("" + BigMath.HALF + " precision " + BigMath.HALF.scale()); > System.out.println("" + rootThousand0 + " precision " + rootThousand0.scale()); > System.out.println("Math.pow(1000.0d,0.5d) " + Math.pow(1000.0d,0.5d)); > > BigDecimal thousand = BigMath.THOUSAND.setScale(100); > BigDecimal half = BigMath.HALF.setScale(100); > BigDecimal rootThousand1 = BigFunction.POW.invoke( > thousand, > half); > System.out.println("" + rootThousand1 + " precision " + rootThousand1.scale()); > > BigDecimal rootTwo = BigFunction.POW.invoke( > BigMath.TWO, > BigMath.HALF); > System.out.println("" + rootTwo + " precision " + rootTwo.scale()); > System.out.println("Math.pow(2.0d,0.5d) " + Math.pow(2.0d,0.5d)); > > > TIA for any help or guidance. > > Andy > http://www.geog.leeds.ac.uk/people/a.turner/ > > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2010-04-14 18:42:46
|
You should look at precision rather than scale. If you look at the BigFunction source code you'll se that most of the implementations either delegate to BigDecimal or to PrimitiveFunction. When it delegates to PrimitiveFunction the precision is given by double otherwise MathContext.DECIMAL128 is used. You cannot control this. Did you notice the RationalNumber class? http://ojalgo.org/generated/org/ojalgo/scalar/RationalNumber.html /Anders On 14 apr 2010, at 17.50, Andy Turner wrote: > With functions how do I know what precision is returned and can a specific precision be requested? > > Running the following code for example shows me that by default rootThousand0 is returned with a scale of 48 where as the rootTwo is returned with a scale of 52. Setting the scale of what is input seems not to have an effect. > > BigDecimal rootThousand0 = BigFunction.POW.invoke( > BigMath.THOUSAND, > BigMath.HALF); > System.out.println("" + BigMath.THOUSAND + " precision " + BigMath.THOUSAND.scale()); > System.out.println("" + BigMath.HALF + " precision " + BigMath.HALF.scale()); > System.out.println("" + rootThousand0 + " precision " + rootThousand0.scale()); > System.out.println("Math.pow(1000.0d,0.5d) " + Math.pow(1000.0d,0.5d)); > > BigDecimal thousand = BigMath.THOUSAND.setScale(100); > BigDecimal half = BigMath.HALF.setScale(100); > BigDecimal rootThousand1 = BigFunction.POW.invoke( > thousand, > half); > System.out.println("" + rootThousand1 + " precision " + rootThousand1.scale()); > > BigDecimal rootTwo = BigFunction.POW.invoke( > BigMath.TWO, > BigMath.HALF); > System.out.println("" + rootTwo + " precision " + rootTwo.scale()); > System.out.println("Math.pow(2.0d,0.5d) " + Math.pow(2.0d,0.5d)); > > > TIA for any help or guidance. > > Andy > http://www.geog.leeds.ac.uk/people/a.turner/ > > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Andy T. <A.G...@le...> - 2010-04-14 16:14:23
|
With functions how do I know what precision is returned and can a specific precision be requested? Running the following code for example shows me that by default rootThousand0 is returned with a scale of 48 where as the rootTwo is returned with a scale of 52. Setting the scale of what is input seems not to have an effect. BigDecimal rootThousand0 = BigFunction.POW.invoke( BigMath.THOUSAND, BigMath.HALF); System.out.println("" + BigMath.THOUSAND + " precision " + BigMath.THOUSAND.scale()); System.out.println("" + BigMath.HALF + " precision " + BigMath.HALF.scale()); System.out.println("" + rootThousand0 + " precision " + rootThousand0.scale()); System.out.println("Math.pow(1000.0d,0.5d) " + Math.pow(1000.0d,0.5d)); BigDecimal thousand = BigMath.THOUSAND.setScale(100); BigDecimal half = BigMath.HALF.setScale(100); BigDecimal rootThousand1 = BigFunction.POW.invoke( thousand, half); System.out.println("" + rootThousand1 + " precision " + rootThousand1.scale()); BigDecimal rootTwo = BigFunction.POW.invoke( BigMath.TWO, BigMath.HALF); System.out.println("" + rootTwo + " precision " + rootTwo.scale()); System.out.println("Math.pow(2.0d,0.5d) " + Math.pow(2.0d,0.5d)); TIA for any help or guidance. Andy http://www.geog.leeds.ac.uk/people/a.turner/ |
From: Andy T. <A.G...@le...> - 2010-04-14 11:55:00
|
Found it: BigFunction.TAN.invoke(BigDecimal); |
From: Andy T. <A.G...@le...> - 2010-04-14 11:31:18
|
My name is Andy and I am a researcher based at the University of Leeds in the UK. I am developing a vector library for arbitrary precision geographical work and think I could make good use of ojalgo. So, thanks very much for this :-) Where are the methods from the class: org.ojalgo.BigUtils ? http://ojalgo.org/generated/org/ojalgo/BigUtils.html First off I am looking for tan(Number). Best wishes and thanks again, Andy http://www.geog.leeds.ac.uk/people/a.turner/ |
From: Anders P. <an...@op...> - 2010-04-12 18:55:59
|
ojAlgo can handle LP and QP problems. In addition to that there is a MIP solver (master algorithm with the LP or QP solvers as slaves) that sometimes work. /Anders On 9 apr 2010, at 12.22, kr...@Ma... wrote: > Hello list members, > > i'd like to know whether this minimization problem is resolvable with > ojAlgo. I don't know at all how to get started with it. > > I have a set of points P in 3d-space and a special point Q which is a > reference point for the minimization problem: The goal is to find a > hyperplane H so that the sum of distances from H to all points in P is > minimal. Constraint: For every p element of P distance(p, Q) must be <= > distance(H, Q). > To illustrate the problem I plotted an example in 2d-space: > http://www.savyon.de/share/minimization.png > > > Many thanks in advance, > > Timo > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Anders P. <an...@op...> - 2010-04-12 18:31:49
|
Don't think you've done anything wrong. I've looked briefly at your test case and can already conclude that the IntegerSolver does not work properly for maximization problems (all the test cases are minimization problems). Immediately fixed one part of the problem, but it still doesn't work... I'll definitely look into this some more, but I'm a little short on time currently. It may take some time. You can turn on debugging with GenericSolver.DEBUG = true; Once you've called model.maximise(); the problem is already solved, and the solution written back to your variables. You may simply System.out.println(model); go "see" the results. This way you don't get access to the OptimisationState. If you want to solve the problem with explicit access to the Solver and Result you'd do something like this: model.setMaximisation(true); final OptimisationSolver solver = model.getDefaultSolver(); final Result result = solver.solve(); /Anders On 11 apr 2010, at 23.07, Luke Lindsay wrote: > I am trying to solve a simple knapsack problem (maximise value given > weight limit) with ojalgo. See code below. The code works as I would > expected when var[i] are not set to integers. I.e. the result is > "OPTIMAL (0) { 1.0, 0.25, 3.0, 0.0, 0.0, 0.75 }" which I interpret as > meaning "take one unit of item 0 and 0.25 of item 1". > > I want to restrict var[i] to being 0 or 1. But when I uncomment the > line "vars[i].setInteger(true);", I get "OPTIMAL (1) { 0.0, 0.0, 0.0, > 3.0, 0.0, 1.0, 1.0 }". I was expecting "OPTIMAL (0) { 1.0, 0.0, 0..." > i.e. "take one unit of item 0 and none of item 1". > > Am I doing something wrong here? > > > ........................................................................................................................................... > package knapsack; > > > import static org.ojalgo.constant.BigMath.*; > > import java.math.BigDecimal; > import org.ojalgo.optimisation.*; > import org.ojalgo.optimisation.OptimisationSolver.Result; > import org.ojalgo.optimisation.linear.LinearExpressionsModel; > > public class Knapsack { > > static class Item{ > final BigDecimal value; > final BigDecimal weight; > public Item(int value, int weight) { > this.value = new BigDecimal(value); > this.weight = new BigDecimal(weight); > } > } > > > public static void main(String[] args) { > > BigDecimal maxWeight = new BigDecimal(3); > Item[] items = {new Item(20, 2), new Item(30, 4)}; > > Variable[] vars = new Variable[items.length]; > for(int i =0; i < vars.length; i++){ > vars[i] = new Variable(String.valueOf(i)); > //vars[i].setInteger(true); > > vars[i].upper(ONE).lower(ZERO); > vars[i].setContributionWeight(items[i].value); > } > > > LinearExpressionsModel model = new LinearExpressionsModel(vars); > Expression totalWeight = model.addEmptyLinearExpression("total weight"); > > for(int i =0; i < items.length; i++){ > totalWeight.setLinearFactor(i, items[i].weight); > } > totalWeight.setUpperLimit(maxWeight); > totalWeight.setLowerLimit(ZERO); > > > System.out.println(totalWeight); > > model.maximise(); > OptimisationSolver solver = model.getDefaultSolver(); > > Result result = solver.solve(); > System.out.println(result); > System.out.println(model.maximise()); > System.out.println(model.minimise()); > } > } > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Luke L. <luk...@gm...> - 2010-04-11 21:07:58
|
I am trying to solve a simple knapsack problem (maximise value given weight limit) with ojalgo. See code below. The code works as I would expected when var[i] are not set to integers. I.e. the result is "OPTIMAL (0) { 1.0, 0.25, 3.0, 0.0, 0.0, 0.75 }" which I interpret as meaning "take one unit of item 0 and 0.25 of item 1". I want to restrict var[i] to being 0 or 1. But when I uncomment the line "vars[i].setInteger(true);", I get "OPTIMAL (1) { 0.0, 0.0, 0.0, 3.0, 0.0, 1.0, 1.0 }". I was expecting "OPTIMAL (0) { 1.0, 0.0, 0..." i.e. "take one unit of item 0 and none of item 1". Am I doing something wrong here? ......................................................................................................................................... package knapsack; import static org.ojalgo.constant.BigMath.*; import java.math.BigDecimal; import org.ojalgo.optimisation.*; import org.ojalgo.optimisation.OptimisationSolver.Result; import org.ojalgo.optimisation.linear.LinearExpressionsModel; public class Knapsack { static class Item{ final BigDecimal value; final BigDecimal weight; public Item(int value, int weight) { this.value = new BigDecimal(value); this.weight = new BigDecimal(weight); } } public static void main(String[] args) { BigDecimal maxWeight = new BigDecimal(3); Item[] items = {new Item(20, 2), new Item(30, 4)}; Variable[] vars = new Variable[items.length]; for(int i =0; i < vars.length; i++){ vars[i] = new Variable(String.valueOf(i)); //vars[i].setInteger(true); vars[i].upper(ONE).lower(ZERO); vars[i].setContributionWeight(items[i].value); } LinearExpressionsModel model = new LinearExpressionsModel(vars); Expression totalWeight = model.addEmptyLinearExpression("total weight"); for(int i =0; i < items.length; i++){ totalWeight.setLinearFactor(i, items[i].weight); } totalWeight.setUpperLimit(maxWeight); totalWeight.setLowerLimit(ZERO); System.out.println(totalWeight); model.maximise(); OptimisationSolver solver = model.getDefaultSolver(); Result result = solver.solve(); System.out.println(result); System.out.println(model.maximise()); System.out.println(model.minimise()); } } |
From: <kr...@Ma...> - 2010-04-09 10:22:26
|
Hello list members, i'd like to know whether this minimization problem is resolvable with ojAlgo. I don't know at all how to get started with it. I have a set of points P in 3d-space and a special point Q which is a reference point for the minimization problem: The goal is to find a hyperplane H so that the sum of distances from H to all points in P is minimal. Constraint: For every p element of P distance(p, Q) must be <= distance(H, Q). To illustrate the problem I plotted an example in 2d-space: http://www.savyon.de/share/minimization.png Many thanks in advance, Timo |