ojalgo-user Mailing List for oj! Algorithms (Page 7)
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: Anders P. <an...@op...> - 2015-04-28 22:06:55
|
I think you misinterpret “binary function” http://en.wikipedia.org/wiki/Binary_function http://ojalgo.org/generated/org/ojalgo/function/BinaryFunction.html Did you bother to look at UnaryFunction, BinaryFunction and the other interfaces/classed in that package? > On 28 apr 2015, at 23:24, Argyrouska Bob <esp...@gm...> wrote: > > Hi, > > It seems a little hard to find any examples in the Javadocs. How exactly you define an exponential operation (not a binary one like XOR ^) using a BinaryFunction? > > Thanks again for your support > > On 27 April 2015 at 22:43, Anders Peterson <an...@op...> wrote: > Rounding can be done using UnaryFunction - just create an instance that does what you want. The class NumberContext can give you a function that may suit you. Instantiate a NumberContext and then call get***Function() > > There’s also the SCALE function of PrimitiveFunction. When/if you specify the parameter it turns into a unary function. > > I think you should switch from using BasicMatrix to MatrixStore/PhysicalStore. > > For “pow” you need a binary function... > > fillMatching(Access1D<? extends Number>) > fillMatching(Access1D<Double>, BinaryFunction<Double>, Access1D<Double>) > fillMatching(Access1D<Double>, BinaryFunction<Double>, Double) > fillMatching(Double, BinaryFunction<Double>, Access1D<Double>) > > > > On 27 apr 2015, at 20:30, Argyrouska Bob <esp...@gm...> wrote: > > > > Sorry, > > > > Thanks for your prompt reply. > > Maybe I didn't make myself clear. I was referring to exponential similar to what native Java Math.pow() does. > > What I am looking for is: > > > > BasicMatrix tA, tB; > > tA.pow(tB); or tA.pow(2.0); > > > > which will eventually lead to tA^x, where x=element from tB (applied for each element) or a constant value. > > Secondly a round function similar to what native Java Math.round() offers. > > Meaning: > > > > BasicMatrix tA; > > tA.round(RoundindMode); > > > > which will result in rounding each element of tA to RoundingMode, where RoundingMode=FLOOR, CEILING etc > > Are these possible using UnaryFunctions? > > > > Thanks > > > > On 27 April 2015 at 20:00, Anders Peterson <an...@op...> wrote: > > Sorry, I just noticed you were using BasicMatrix. It works a little different there (a somewhat limited set of functionality) partly because BasicMatrix instances are immutable. It does have a modify-method: > > > > BasicMatrix modify(UnaryFunction<? extends Number>); > > > > > > > > > > > On 27 apr 2015, at 18:51, Anders Peterson <an...@op...> wrote: > > > > > > Do you want to modify matrix elements? > > > > > > Everything that implements Access2D.Modifiable has these methods: > > > > > > modifyColumn(long, long, UnaryFunction<N>) > > > modifyDiagonal(long, long, UnaryFunction<N>) > > > modifyOne(long, long, UnaryFunction<N>) > > > modifyOne(long, UnaryFunction<N>) > > > modifyRange(long, long, UnaryFunction<N>) > > > modifyRow(long, long, UnaryFunction<N>) > > > > > > If you’re using primitive double elements you’ll find a predefined set of functions in org.ojalgo.function.PrimitiveFunction > > > > > > The PhysicalStore.Factory also provides access to that set of functions. > > > > > > If you don’t find what you need you just create a custom UnaryFunction implementation. > > > > > > /Anders > > > > > > > > >> On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: > > >> > > >> Hello, > > >> > > >> I am a new member and still practicing with library but what surprises me is that I haven't found support for power functions or round to a BasicMatrix data type. Is this true or it's named somewhat different? > > >> > > >> Thanks and regards, > > >> silver > > >> > > >> > > >> ------------------------------------------------------------------------------ > > >> One dashboard for servers and applications across Physical-Virtual-Cloud > > >> Widest out-of-the-box monitoring support with 50+ applications > > >> Performance metrics, stats and reports that give you Actionable Insights > > >> Deep dive visibility with transaction tracing using APM Insight. > > >> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > > >> ojAlgo-user mailing list > > >> ojA...@li... > > >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > ------------------------------------------------------------------------------ > > One dashboard for servers and applications across Physical-Virtual-Cloud > > Widest out-of-the-box monitoring support with 50+ applications > > Performance metrics, stats and reports that give you Actionable Insights > > Deep dive visibility with transaction tracing using APM Insight. > > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > > _______________________________________________ > > ojAlgo-user mailing list > > ojAlgo-user@lists..sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > -- > > Reality leaves a lot to imagination. > > ------------------------------------------------------------------------------ > > One dashboard for servers and applications across Physical-Virtual-Cloud > > Widest out-of-the-box monitoring support with 50+ applications > > Performance metrics, stats and reports that give you Actionable Insights > > Deep dive visibility with transaction tracing using APM Insight. > > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > > ojAlgo-user mailing list > > ojAlgo-user@lists..sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > -- > Reality leaves a lot to imagination. > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Argyrouska B. <esp...@gm...> - 2015-04-28 21:24:52
|
Hi, It seems a little hard to find any examples in the Javadocs. How exactly you define an exponential operation (not a binary one like XOR ^) using a BinaryFunction? Thanks again for your support On 27 April 2015 at 22:43, Anders Peterson <an...@op...> wrote: > Rounding can be done using UnaryFunction - just create an instance that > does what you want. The class NumberContext can give you a function that > may suit you. Instantiate a NumberContext and then call get***Function() > > There’s also the SCALE function of PrimitiveFunction. When/if you specify > the parameter it turns into a unary function. > > I think you should switch from using BasicMatrix to > MatrixStore/PhysicalStore. > > For “pow” you need a binary function... > > fillMatching(Access1D<? extends Number>) > fillMatching(Access1D<Double>, BinaryFunction<Double>, Access1D<Double>) > fillMatching(Access1D<Double>, BinaryFunction<Double>, Double) > fillMatching(Double, BinaryFunction<Double>, Access1D<Double>) > > > > On 27 apr 2015, at 20:30, Argyrouska Bob <esp...@gm...> wrote: > > > > Sorry, > > > > Thanks for your prompt reply. > > Maybe I didn't make myself clear. I was referring to exponential similar > to what native Java Math.pow() does. > > What I am looking for is: > > > > BasicMatrix tA, tB; > > tA.pow(tB); or tA.pow(2.0); > > > > which will eventually lead to tA^x, where x=element from tB (applied for > each element) or a constant value. > > Secondly a round function similar to what native Java Math.round() > offers. > > Meaning: > > > > BasicMatrix tA; > > tA.round(RoundindMode); > > > > which will result in rounding each element of tA to RoundingMode, where > RoundingMode=FLOOR, CEILING etc > > Are these possible using UnaryFunctions? > > > > Thanks > > > > On 27 April 2015 at 20:00, Anders Peterson <an...@op...> wrote: > > Sorry, I just noticed you were using BasicMatrix. It works a little > different there (a somewhat limited set of functionality) partly because > BasicMatrix instances are immutable. It does have a modify-method: > > > > BasicMatrix modify(UnaryFunction<? extends Number>); > > > > > > > > > > > On 27 apr 2015, at 18:51, Anders Peterson <an...@op...> > wrote: > > > > > > Do you want to modify matrix elements? > > > > > > Everything that implements Access2D.Modifiable has these methods: > > > > > > modifyColumn(long, long, UnaryFunction<N>) > > > modifyDiagonal(long, long, UnaryFunction<N>) > > > modifyOne(long, long, UnaryFunction<N>) > > > modifyOne(long, UnaryFunction<N>) > > > modifyRange(long, long, UnaryFunction<N>) > > > modifyRow(long, long, UnaryFunction<N>) > > > > > > If you’re using primitive double elements you’ll find a predefined set > of functions in org.ojalgo.function.PrimitiveFunction > > > > > > The PhysicalStore.Factory also provides access to that set of > functions. > > > > > > If you don’t find what you need you just create a custom UnaryFunction > implementation. > > > > > > /Anders > > > > > > > > >> On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: > > >> > > >> Hello, > > >> > > >> I am a new member and still practicing with library but what > surprises me is that I haven't found support for power functions or round > to a BasicMatrix data type. Is this true or it's named somewhat different? > > >> > > >> Thanks and regards, > > >> silver > > >> > > >> > > >> > ------------------------------------------------------------------------------ > > >> One dashboard for servers and applications across > Physical-Virtual-Cloud > > >> Widest out-of-the-box monitoring support with 50+ applications > > >> Performance metrics, stats and reports that give you Actionable > Insights > > >> Deep dive visibility with transaction tracing using APM Insight. > > >> > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > > >> ojAlgo-user mailing list > > >> ojA...@li... > > >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > > > ------------------------------------------------------------------------------ > > One dashboard for servers and applications across Physical-Virtual-Cloud > > Widest out-of-the-box monitoring support with 50+ applications > > Performance metrics, stats and reports that give you Actionable Insights > > Deep dive visibility with transaction tracing using APM Insight. > > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > > _______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > > > -- > > Reality leaves a lot to imagination. > > > ------------------------------------------------------------------------------ > > One dashboard for servers and applications across Physical-Virtual-Cloud > > Widest out-of-the-box monitoring support with 50+ applications > > Performance metrics, stats and reports that give you Actionable Insights > > Deep dive visibility with transaction tracing using APM Insight. > > > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > > ojAlgo-user mailing list > > ojA...@li... > > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > -- Reality leaves a lot to imagination. |
From: Anders P. <an...@op...> - 2015-04-27 19:43:37
|
Rounding can be done using UnaryFunction - just create an instance that does what you want. The class NumberContext can give you a function that may suit you. Instantiate a NumberContext and then call get***Function() There’s also the SCALE function of PrimitiveFunction. When/if you specify the parameter it turns into a unary function. I think you should switch from using BasicMatrix to MatrixStore/PhysicalStore. For “pow” you need a binary function... fillMatching(Access1D<? extends Number>) fillMatching(Access1D<Double>, BinaryFunction<Double>, Access1D<Double>) fillMatching(Access1D<Double>, BinaryFunction<Double>, Double) fillMatching(Double, BinaryFunction<Double>, Access1D<Double>) > On 27 apr 2015, at 20:30, Argyrouska Bob <esp...@gm...> wrote: > > Sorry, > > Thanks for your prompt reply. > Maybe I didn't make myself clear. I was referring to exponential similar to what native Java Math.pow() does. > What I am looking for is: > > BasicMatrix tA, tB; > tA.pow(tB); or tA.pow(2.0); > > which will eventually lead to tA^x, where x=element from tB (applied for each element) or a constant value. > Secondly a round function similar to what native Java Math.round() offers. > Meaning: > > BasicMatrix tA; > tA.round(RoundindMode); > > which will result in rounding each element of tA to RoundingMode, where RoundingMode=FLOOR, CEILING etc > Are these possible using UnaryFunctions? > > Thanks > > On 27 April 2015 at 20:00, Anders Peterson <an...@op...> wrote: > Sorry, I just noticed you were using BasicMatrix. It works a little different there (a somewhat limited set of functionality) partly because BasicMatrix instances are immutable. It does have a modify-method: > > BasicMatrix modify(UnaryFunction<? extends Number>); > > > > > > On 27 apr 2015, at 18:51, Anders Peterson <an...@op...> wrote: > > > > Do you want to modify matrix elements? > > > > Everything that implements Access2D.Modifiable has these methods: > > > > modifyColumn(long, long, UnaryFunction<N>) > > modifyDiagonal(long, long, UnaryFunction<N>) > > modifyOne(long, long, UnaryFunction<N>) > > modifyOne(long, UnaryFunction<N>) > > modifyRange(long, long, UnaryFunction<N>) > > modifyRow(long, long, UnaryFunction<N>) > > > > If you’re using primitive double elements you’ll find a predefined set of functions in org.ojalgo.function.PrimitiveFunction > > > > The PhysicalStore.Factory also provides access to that set of functions. > > > > If you don’t find what you need you just create a custom UnaryFunction implementation. > > > > /Anders > > > > > >> On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: > >> > >> Hello, > >> > >> I am a new member and still practicing with library but what surprises me is that I haven't found support for power functions or round to a BasicMatrix data type. Is this true or it's named somewhat different? > >> > >> Thanks and regards, > >> silver > >> > >> > >> ------------------------------------------------------------------------------ > >> One dashboard for servers and applications across Physical-Virtual-Cloud > >> Widest out-of-the-box monitoring support with 50+ applications > >> Performance metrics, stats and reports that give you Actionable Insights > >> Deep dive visibility with transaction tracing using APM Insight. > >> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > >> ojAlgo-user mailing list > >> ojA...@li... > >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > -- > Reality leaves a lot to imagination. > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Argyrouska B. <esp...@gm...> - 2015-04-27 18:30:34
|
Sorry, Thanks for your prompt reply. Maybe I didn't make myself clear. I was referring to exponential similar to what native Java Math.pow() does. What I am looking for is: BasicMatrix tA, tB; tA.pow(tB); or tA.pow(2.0); which will eventually lead to tA^x, where x=element from tB (applied for each element) or a constant value. Secondly a round function similar to what native Java Math.round() offers. Meaning: BasicMatrix tA; tA.round(RoundindMode); which will result in rounding each element of tA to RoundingMode, where RoundingMode=FLOOR, CEILING etc Are these possible using UnaryFunctions? Thanks On 27 April 2015 at 20:00, Anders Peterson <an...@op...> wrote: > Sorry, I just noticed you were using BasicMatrix. It works a little > different there (a somewhat limited set of functionality) partly because > BasicMatrix instances are immutable. It does have a modify-method: > > BasicMatrix modify(UnaryFunction<? extends Number>); > > > > > > On 27 apr 2015, at 18:51, Anders Peterson <an...@op...> wrote: > > > > Do you want to modify matrix elements? > > > > Everything that implements Access2D.Modifiable has these methods: > > > > modifyColumn(long, long, UnaryFunction<N>) > > modifyDiagonal(long, long, UnaryFunction<N>) > > modifyOne(long, long, UnaryFunction<N>) > > modifyOne(long, UnaryFunction<N>) > > modifyRange(long, long, UnaryFunction<N>) > > modifyRow(long, long, UnaryFunction<N>) > > > > If you’re using primitive double elements you’ll find a predefined set > of functions in org.ojalgo.function.PrimitiveFunction > > > > The PhysicalStore.Factory also provides access to that set of functions. > > > > If you don’t find what you need you just create a custom UnaryFunction > implementation. > > > > /Anders > > > > > >> On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: > >> > >> Hello, > >> > >> I am a new member and still practicing with library but what surprises > me is that I haven't found support for power functions or round to a > BasicMatrix data type. Is this true or it's named somewhat different? > >> > >> Thanks and regards, > >> silver > >> > >> > >> > ------------------------------------------------------------------------------ > >> One dashboard for servers and applications across Physical-Virtual-Cloud > >> Widest out-of-the-box monitoring support with 50+ applications > >> Performance metrics, stats and reports that give you Actionable Insights > >> Deep dive visibility with transaction tracing using APM Insight. > >> > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > >> ojAlgo-user mailing list > >> ojA...@li... > >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > -- Reality leaves a lot to imagination. |
From: Anders P. <an...@op...> - 2015-04-27 17:10:15
|
Do you want to modify matrix elements? Everything that implements Access2D.Modifiable has these methods: modifyColumn(long, long, UnaryFunction<N>) modifyDiagonal(long, long, UnaryFunction<N>) modifyOne(long, long, UnaryFunction<N>) modifyOne(long, UnaryFunction<N>) modifyRange(long, long, UnaryFunction<N>) modifyRow(long, long, UnaryFunction<N>) If you’re using primitive double elements you’ll find a predefined set of functions in org.ojalgo.function.PrimitiveFunction The PhysicalStore.Factory also provides access to that set of functions. If you don’t find what you need you just create a custom UnaryFunction implementation. /Anders > On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: > > Hello, > > I am a new member and still practicing with library but what surprises me is that I haven't found support for power functions or round to a BasicMatrix data type. Is this true or it's named somewhat different? > > Thanks and regards, > silver > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2015-04-27 17:10:14
|
Sorry, I just noticed you were using BasicMatrix. It works a little different there (a somewhat limited set of functionality) partly because BasicMatrix instances are immutable. It does have a modify-method: BasicMatrix modify(UnaryFunction<? extends Number>); > On 27 apr 2015, at 18:51, Anders Peterson <an...@op...> wrote: > > Do you want to modify matrix elements? > > Everything that implements Access2D.Modifiable has these methods: > > modifyColumn(long, long, UnaryFunction<N>) > modifyDiagonal(long, long, UnaryFunction<N>) > modifyOne(long, long, UnaryFunction<N>) > modifyOne(long, UnaryFunction<N>) > modifyRange(long, long, UnaryFunction<N>) > modifyRow(long, long, UnaryFunction<N>) > > If you’re using primitive double elements you’ll find a predefined set of functions in org.ojalgo.function.PrimitiveFunction > > The PhysicalStore.Factory also provides access to that set of functions. > > If you don’t find what you need you just create a custom UnaryFunction implementation. > > /Anders > > >> On 27 apr 2015, at 18:29, Argyrouska Bob <esp...@gm...> wrote: >> >> Hello, >> >> I am a new member and still practicing with library but what surprises me is that I haven't found support for power functions or round to a BasicMatrix data type. Is this true or it's named somewhat different? >> >> Thanks and regards, >> silver >> >> >> ------------------------------------------------------------------------------ >> One dashboard for servers and applications across Physical-Virtual-Cloud >> Widest out-of-the-box monitoring support with 50+ applications >> Performance metrics, stats and reports that give you Actionable Insights >> Deep dive visibility with transaction tracing using APM Insight. >> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > |
From: Argyrouska B. <esp...@gm...> - 2015-04-27 16:29:33
|
Hello, I am a new member and still practicing with library but what surprises me is that I haven't found support for power functions or round to a BasicMatrix data type. Is this true or it's named somewhat different? Thanks and regards, silver |
From: Anders P. <an...@op...> - 2015-03-01 09:00:07
|
It's a VERY SIMPLE test, but it could help you decide if ojAlgo suits your needs or not. https://code.google.com/p/ojalgo/wiki/ConvexSolverPerformance |
From: Anders P. <an...@op...> - 2015-02-19 04:55:56
|
You cannot add constraints on absolute variable values. You have to rethink your model. Optimatika does NOT offer this kind of modelling help as a free service. /Anders > On 18 feb 2015, at 19:02, Anthony Edwards <ant...@al...> wrote: > > I have an expressions based model and would like to add a constraint > such that the sum of the absolute values of the variables is set to a > specific value/level. How do I formulate this in oj-algo? IOve been > looking at this for a while and cant see how to actually formulate this > in terms of an expression I can add to the model .... > > Any help very much appreciated! > > Thanks > > Tony > > > On 16/02/15 13:11, Anders Peterson wrote: >> This is a modelling question not directly related to ojAlgo, Strictly speaking you're off topic for this mailing list, but I'm leaning towards allowing it if the discussion context is "how do I do this with ojAlgo". I will however only participate if the discussion leads to more concrete questions regarding ojAlgo. >> >> /Anders >> >> >> >>> On 16 feb 2015, at 13:01, Anthony Edwards <ant...@al...> wrote: >>> >>> Hi >>> >>> I am using an expressions based model (for a portfolio optimisation >>> problem) and can add a constraint such that the sum of the weights in >>> the portfolio is equals to 1 as follows: >>> >>> Expression balanceExpr = model.addExpression("Balance"); >>> for (int i=0; i<ers.length; i++) >>> balanceExpr.setLinearFactor(i, BigMath.ONE); >>> balanceExpr.lower(BigMath.ONE); >>> balanceExpr.upper(BigMath.ONE); >>> >>> What I would like to do is add another constrains such that the sum of >>> the absolute values of the weights is less than 2. Any idea how I can >>> do this? There is no setAbsoluteValueLinearFactor function or any way >>> of doing this as far as I can see. >>> >>> Any pointers would be gratefully appreciated! >>> >>> Thanks >>> >>> Tony >>> >>> ------------------------------------------------------------------------------ >>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >>> with Interactivity, Sharing, Native Excel Exports, App Integration & more >>> Get technology previously reserved for billion-dollar corporations, FREE >>> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >> >> ------------------------------------------------------------------------------ >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >> with Interactivity, Sharing, Native Excel Exports, App Integration & more >> Get technology previously reserved for billion-dollar corporations, FREE >> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Anthony E. <ant...@al...> - 2015-02-18 18:02:15
|
I have an expressions based model and would like to add a constraint such that the sum of the absolute values of the variables is set to a specific value/level. How do I formulate this in oj-algo? IOve been looking at this for a while and cant see how to actually formulate this in terms of an expression I can add to the model .... Any help very much appreciated! Thanks Tony On 16/02/15 13:11, Anders Peterson wrote: > This is a modelling question not directly related to ojAlgo, Strictly speaking you're off topic for this mailing list, but I'm leaning towards allowing it if the discussion context is "how do I do this with ojAlgo". I will however only participate if the discussion leads to more concrete questions regarding ojAlgo. > > /Anders > > > >> On 16 feb 2015, at 13:01, Anthony Edwards <ant...@al...> wrote: >> >> Hi >> >> I am using an expressions based model (for a portfolio optimisation >> problem) and can add a constraint such that the sum of the weights in >> the portfolio is equals to 1 as follows: >> >> Expression balanceExpr = model.addExpression("Balance"); >> for (int i=0; i<ers.length; i++) >> balanceExpr.setLinearFactor(i, BigMath.ONE); >> balanceExpr.lower(BigMath.ONE); >> balanceExpr.upper(BigMath.ONE); >> >> What I would like to do is add another constrains such that the sum of >> the absolute values of the weights is less than 2. Any idea how I can >> do this? There is no setAbsoluteValueLinearFactor function or any way >> of doing this as far as I can see. >> >> Any pointers would be gratefully appreciated! >> >> Thanks >> >> Tony >> >> ------------------------------------------------------------------------------ >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >> with Interactivity, Sharing, Native Excel Exports, App Integration & more >> Get technology previously reserved for billion-dollar corporations, FREE >> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anthony E. <ant...@al...> - 2015-02-17 13:33:32
|
Hi I am doing a simple expression based model but wish to add a constraint to the model such that the sum of absolute values of the variables must equal a fixed value. I can see that I can do like this ... final Expression tmpBalanceExpression = model.addExpression("balance"); for (int i = 0; i < vars.length; i++) { tmpBalanceExpression.setLinearFactor(i, ONE); } ... to set the total value of all the variables to 1, but how can I set the sum of the absolute values of those variables to a value? Any ideas? Thanks Tony |
From: Stefan K. <st...@gm...> - 2015-02-16 20:58:11
|
Hello Andres, thank you for your fast reply. If I do not need to consider the documentation of QuadraticSolver/ConvexSolver, everything works fine and I have no further questions. Thank you Stefan Am 16.02.2015 um 13:34 schrieb Anders Peterson: > You do not need to consider the documentation of any specific solver when using ExpressionsBasedModel (but you do need to remember that currently/still no solver can handle quadratic constraints). > > ExpressionsBasedModel.minimise() will minimise whatever model you built. What did you build and how was anything disregarded? > > The entire org/ojalgo/optimisation/quadratic package has been replaced by org/ojalgo/optimisation/convex. Most likely the site and docs still need some updates to reflect that change. As a user of ExpressionsBasedModel you do not need to worry about that > > > /Anders > > > >> On 16 feb 2015, at 08:07, Stefan Kiesel <st...@gm...> wrote: >> >> Hello, >> >> I'm trying to solve a quadratic optimisation problem. The qp-link below Main ingredients at ojalgo.org leads to http://ojalgo.org/generated/org/ojalgo/optimisation/quadratic/QuadraticSolver.html . This documentation says, that ojalgo solves qps of the form >> >> min 1/2 x^T Q x - c^T x >> >> I've created an ExpressionsBasedModel and solved it by calling ExpressionsBasedModel.minimise(). The solution seems to be correct but the factor 1/2 is ignored. Does ExpressionsBasedModel.minimise() minimise qps of the form >> >> min x^T Q x - c^T x >> >> or did I missunderstand something? >> >> Thanks >> Stefan >> ------------------------------------------------------------------------------ >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >> with Interactivity, Sharing, Native Excel Exports, App Integration & more >> Get technology previously reserved for billion-dollar corporations, FREE >> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft. http://www.avast.com |
From: Anthony E. <ant...@al...> - 2015-02-16 13:30:25
|
Hi Anders. Thanks for that - it certainly is really a 'how do I do this with ojalgo' and in particular will benefit anyone using ojalgo for long/short portfolio optimisation problems where they wish to constrain the limits on the degree of long/short bias that the portfolio can have. I guess that its a case of adding an Expression to the ExpressionBasedModel that encapsulates this 'sum of absolute values' modelling formulation. I have looked at the very flexible setLinearFactor methods for the Expression class and am wondering if i need to somehow use the setLinearFactors(List<Variable>, Access1D) or possibly create a variable that is the absolute value of the existing variable (the weights of the portfolio in this specific case) and then use the setLinearFactor(Variable, Number) method of the Expression class. If I can understand how to code this withing the ojalgo framework I'm sure it will benefit the community as I've looked into this for a while and I must be missing something. Thanks - appreciate your time and help with this. Tony On 16/02/15 13:11, Anders Peterson wrote: > This is a modelling question not directly related to ojAlgo, Strictly speaking you're off topic for this mailing list, but I'm leaning towards allowing it if the discussion context is "how do I do this with ojAlgo". I will however only participate if the discussion leads to more concrete questions regarding ojAlgo. > > /Anders > > > >> On 16 feb 2015, at 13:01, Anthony Edwards <ant...@al...> wrote: >> >> Hi >> >> I am using an expressions based model (for a portfolio optimisation >> problem) and can add a constraint such that the sum of the weights in >> the portfolio is equals to 1 as follows: >> >> Expression balanceExpr = model.addExpression("Balance"); >> for (int i=0; i<ers.length; i++) >> balanceExpr.setLinearFactor(i, BigMath.ONE); >> balanceExpr.lower(BigMath.ONE); >> balanceExpr.upper(BigMath.ONE); >> >> What I would like to do is add another constrains such that the sum of >> the absolute values of the weights is less than 2. Any idea how I can >> do this? There is no setAbsoluteValueLinearFactor function or any way >> of doing this as far as I can see. >> >> Any pointers would be gratefully appreciated! >> >> Thanks >> >> Tony >> >> ------------------------------------------------------------------------------ >> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server >> from Actuate! Instantly Supercharge Your Business Reports and Dashboards >> with Interactivity, Sharing, Native Excel Exports, App Integration & more >> Get technology previously reserved for billion-dollar corporations, FREE >> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2015-02-16 13:11:35
|
This is a modelling question not directly related to ojAlgo, Strictly speaking you're off topic for this mailing list, but I'm leaning towards allowing it if the discussion context is "how do I do this with ojAlgo". I will however only participate if the discussion leads to more concrete questions regarding ojAlgo. /Anders > On 16 feb 2015, at 13:01, Anthony Edwards <ant...@al...> wrote: > > Hi > > I am using an expressions based model (for a portfolio optimisation > problem) and can add a constraint such that the sum of the weights in > the portfolio is equals to 1 as follows: > > Expression balanceExpr = model.addExpression("Balance"); > for (int i=0; i<ers.length; i++) > balanceExpr.setLinearFactor(i, BigMath.ONE); > balanceExpr.lower(BigMath.ONE); > balanceExpr.upper(BigMath.ONE); > > What I would like to do is add another constrains such that the sum of > the absolute values of the weights is less than 2. Any idea how I can > do this? There is no setAbsoluteValueLinearFactor function or any way > of doing this as far as I can see. > > Any pointers would be gratefully appreciated! > > Thanks > > Tony > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |
From: Anders P. <an...@op...> - 2015-02-16 12:35:48
|
You do not need to consider the documentation of any specific solver when using ExpressionsBasedModel (but you do need to remember that currently/still no solver can handle quadratic constraints). ExpressionsBasedModel.minimise() will minimise whatever model you built. What did you build and how was anything disregarded? The entire org/ojalgo/optimisation/quadratic package has been replaced by org/ojalgo/optimisation/convex. Most likely the site and docs still need some updates to reflect that change. As a user of ExpressionsBasedModel you do not need to worry about that /Anders > On 16 feb 2015, at 08:07, Stefan Kiesel <st...@gm...> wrote: > > Hello, > > I'm trying to solve a quadratic optimisation problem. The qp-link below Main ingredients at ojalgo.org leads to http://ojalgo.org/generated/org/ojalgo/optimisation/quadratic/QuadraticSolver.html . This documentation says, that ojalgo solves qps of the form > > min 1/2 x^T Q x - c^T x > > I've created an ExpressionsBasedModel and solved it by calling ExpressionsBasedModel.minimise(). The solution seems to be correct but the factor 1/2 is ignored. Does ExpressionsBasedModel.minimise() minimise qps of the form > > min x^T Q x - c^T x > > or did I missunderstand something? > > Thanks > Stefan > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anthony E. <ant...@al...> - 2015-02-16 12:21:32
|
Hi I am using an expressions based model (for a portfolio optimisation problem) and can add a constraint such that the sum of the weights in the portfolio is equals to 1 as follows: Expression balanceExpr = model.addExpression("Balance"); for (int i=0; i<ers.length; i++) balanceExpr.setLinearFactor(i, BigMath.ONE); balanceExpr.lower(BigMath.ONE); balanceExpr.upper(BigMath.ONE); What I would like to do is add another constrains such that the sum of the absolute values of the weights is less than 2. Any idea how I can do this? There is no setAbsoluteValueLinearFactor function or any way of doing this as far as I can see. Any pointers would be gratefully appreciated! Thanks Tony |
From: Stefan K. <st...@gm...> - 2015-02-16 07:07:46
|
Hello, I'm trying to solve a quadratic optimisation problem. The qp-link below Main ingredients at ojalgo.org leads to http://ojalgo.org/generated/ org/ojalgo/optimisation/quadratic/QuadraticSolver.html . This documentation says, that ojalgo solves qps of the form min 1/2 x^T Q x - c^T x I've created an ExpressionsBasedModel and solved it by calling ExpressionsBasedModel.minimise(). The solution seems to be correct but the factor 1/2 is ignored. Does ExpressionsBasedModel.minimise() minimise qps of the form min x^T Q x - c^T x or did I missunderstand something? Thanks Stefan |
From: Uli S. <Uli...@In...> - 2015-02-02 10:22:05
|
Thanks a lot! I updated to v37.1, switched from .solve() (which was removed) to .minimise() and now my program works fine. Thanks a lot for this and for ojAlgo in general! However, pressing the "Download"-button on ojalgo.org still downloads v37.0. I had to go to sourceforge and look for the file directly. Something seems to be wrong on there...? Cheers, Uli Am 31.01.2015 um 21:16 schrieb Anders Peterson: > Very easy to construct test cases and debug using the code examples you sent me. > > Compared to v37 that you used: > > 1) The IntegerSolver no longer creates subproblems that are difficult to solve (the way it did in your case). > > 2) The LinearSolver can now handle problem instances like the ones the IntegerSolver used to create > > 3) The ExpressionsBasedModel (in combination with the IntegerSolver) is now better at identifying when/if it doesn't need to call a solver at all. > > > I've backported the entire org.ojalgo.optimisation.* package(s) to the Java7 branch at GitHub, and I've built and uploaded v37.1 to SourceForge. > > > Please try this and report the results here, > > /Anders > > > >> On 28 jan 2015, at 14:55, Uli Schlachter <Uli...@In...> wrote: >> >> Am 28.01.2015 um 13:00 schrieb Anders Peterson: >>> Have I understood this correct: You have a model with 2 variables and 2 inequality constraints that, at a specific branch-and-bound node, demonstrates the problem? >> >> Yeah, correctly. >> >> However, this model now demonstrates the problem without any branching at all. >> >>> From the output and your comments it seems clear that the problem is with the LinearSolver - it fails to discover/report that a subproblem is infeasible. >>> >>> The output contains this: "Switching to Phase2 with 1 artificial variable(s) still in the basis." >>> >>> ...and then I've noticed that you have not specified an objective function (any/all solutions are equally good). >>> >>> This combination could very well be something that ojAlgo fails to handle. I'll look in to this, but it has to be in a few days or so. >> >> Sure, no hurry. I just want to report my findings and hope that they will be useful to you. Feel free to ignore my problem until you have the time. >> >>> Have you tried specifying an objective function - preferably one that clearly favours some solutions over others? (x is better than y) >> >> Not yet. A quick experiment with various weights didn't change anything (I always got an invalid solution which was claimed to be OPTIMAL, but which solution I get changes with the weights). >> >> I'm now down to this: >> >> ExpressionsBasedModel model = new ExpressionsBasedModel(); >> >> model.addVariable(Variable.make("x").integer(true). >> lower(1).upper(20).weight(1)); >> model.addVariable(Variable.make("y").integer(true). >> upper(-1).weight(-1)); >> >> Expression e = model.addExpression("inequality1"); >> e.setLinearFactor(0, -10); >> e.setLinearFactor(1, -199); >> e.upper(-1); >> >> e = model.addExpression("inequality2"); >> e.setLinearFactor(0, -10); >> e.setLinearFactor(0, -10); >> e.setLinearFactor(1, -200); >> e.upper(-1); >> >> result = model.minimise(); >> >> >> With the weights as in the code above, I even get a solution x=1, y=0, which contradicts y's upper limit of -1. With model.options.validate = true, ojAlgo notices some problem and the above system is unsolvable. >> >> Please note: >> integer(true) on "y" is the key ingredient. If this variable isn't integer, ojAlgo correctly deduces "unsolvable". If both variables have ..integer(false), ojAlgo also deduces "unsolvable". If this variable is integer, ojAlgo claims to find a solution (but validate = true still makes it notice its error). >> >> So the OldIntegerSolver must somehow be involved with the problem as well, I just have no idea how. It must be more than just the relaxation, but what? >> >> Attached is again some small java program. Feel free to ignore it, but it contains the above code and tries to solve this once with model.options.validate = true and once with = false. The result in both cases is different. >> >> The results are the same with the latest git version of ojAlgo. >> >>> /Anders >> >> Cheers, >> Uli >> who can wait a week or two before looking at this again. :-) >> >>>> On 28 jan 2015, at 10:25, Uli Schlachter <Uli...@In...> wrote: >>>> >>>> Hi, >>>> >>>> I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: >>>> >>>> - I reduced the model used to: >>>> >>>> -10*x + -199*y <= -1 >>>> -10*x + -200*y <= -1 >>>> >>>> This still shows the same behavior as the code from my first mail. >>>> >>>> - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: >>>> >>>> 1 <= x <= 20 >>>> y <= -1 >>>> >>>> -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". >>>> >>>> - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) >>>> >>>> - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: >>>> >>>> if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { >>>> // This should not be possible. There is a bug somewhere. >>>> OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + >>>> "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + >>>> myKey.toString() + "\n" + >>>> OldIntegerSolver.this.toString() +"\n" + >>>> tmpModel.toString() +"\n"); >>>> final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); >>>> tmpDefaultSolver.solve(); >>>> OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); >>>> return false; >>>> } >>>> >>>> - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". >>>> >>>> At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. >>>> >>>> Cheers & have a nice week, >>>> Uli >>>> >>>> Am 27.01.2015 um 17:56 schrieb Anders Peterson: >>>>> Most likely the rounding problem/numerical issue is with the LinearSolver. >>>>> >>>>> I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. >>>>> >>>>> To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. >>>>> >>>>> I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. >>>>> >>>>> If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. >>>>> >>>>> If you turn on solver debugging you'll get some info regarding what goes on: >>>>> >>>>> model.options.debug(LinearSolver.class); >>>>> >>>>> or >>>>> >>>>> model.options.debug(IntegerSolver.class); >>>>> >>>>> >>>>> or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. >>>>> >>>>> >>>>> /Anders >>>>> >>>>> >>>>> >>>>>> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>>>>>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >>>>>> >>>>>> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >>>>>> with the latest development version and sadly my project cannot switch >>>>>> from Java 7 to Java 8. >>>>>> >>>>>>> x = 21.0 ~ 21 >>>>>>> y = -1.0 ~ -1 >>>>>>> >>>>>>> Is that what you want? >>>>>> >>>>>> x = 21 and y = -1 is indeed one of my desired solution. >>>>>> >>>>>>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>>>>>> these are a bit sensitive and changing them is not generally >>>>>> recommended, but he "integer" and "solution" number >>>>>>> contexts should be relatively safe to tweak. >>>>>> >>>>>> I don't have much time right now, but I will look more closely into this >>>>>> later. >>>>>> >>>>>> From what I understand right now, "solution" affects how the solution >>>>>> is turned into a BigDecimal. However, I don't see how rounding >>>>>> "19.999.." can get help me here, since the desired value would be 21. >>>>>> >>>>>> The member "integer" sounds more promising. I guess I want something >>>>>> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >>>>>> will experiment with this later. Thanks for the hint. >>>>>> >>>>>>> If you call minimise() rather than solve() does it make a difference? >>>>>> >>>>>> None that matters, but the values in the result change a little. >>>>>> >>>>>> solve(): >>>>>> >>>>>> x = 19.999999999999993 ~ 20 >>>>>> y = -0.9950000000000006 ~ -1 >>>>>> >>>>>> minimise(): >>>>>> >>>>>> x = 20.00000000000000 ~ 20 >>>>>> y = -0.99500000000000 ~ -1 >>>>>> >>>>>>> /Anders >>>>>> >>>>>> Thanks for looking into this. >>>>>> Uli >>>>>> >>>>>>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>>>>>> >>>>>>>> Hi everyone, >>>>>>>> >>>>>>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>>>>>> >>>>>>>> Hopefully the program explains itself, but here is some more text: >>>>>>>> >>>>>>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>>>>>> >>>>>>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>>>>>> >>>>>>>> x = 19.999999999999993 ~ 20 >>>>>>>> y = -0.9950000000000006 ~ -1 >>>>>>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>>>>>> at Solve.main(Solve.java:60) >>>>>>>> >>>>>>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>>>>>> >>>>>>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>>>>>> >>>>>>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>>>>>> >>>>>>>> Cheers, >>>>>>>> Uli >>>>>>>> -- >>>>>>>> - Buck, when, exactly, did you lose your mind? >>>>>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>>>>> An ugly pineapple... But I loved her. >>>>>>>> <Solve.java>------------------------------------------------------------------------------ >>>>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>>>> hub for all things parallel software development, from weekly thought >>>>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>>>>>> ojAlgo-user mailing list >>>>>>>> ojA...@li... >>>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>>> >>>>>>> >>>>>>> ------------------------------------------------------------------------------ >>>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>>> hub for all things parallel software development, from weekly thought >>>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>>>> _______________________________________________ >>>>>>> ojAlgo-user mailing list >>>>>>> ojA...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> - Buck, when, exactly, did you lose your mind? >>>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>>> An ugly pineapple... But I loved her. >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>> hub for all things parallel software development, from weekly thought >>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>>> _______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>> hub for all things parallel software development, from weekly thought >>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>> >>>> >>>> -- >>>> - Buck, when, exactly, did you lose your mind? >>>> - Three months ago. I woke up one morning married to a pineapple. >>>> An ugly pineapple... But I loved her. >>>> <Solve.java><output.txt>------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >>> ------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/ >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >> >> >> -- >> - Buck, when, exactly, did you lose your mind? >> - Three months ago. I woke up one morning married to a pineapple. >> An ugly pineapple... But I loved her. >> <Solve.java>------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > -- "In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move." |
From: Anders P. <an...@op...> - 2015-01-31 20:16:35
|
Very easy to construct test cases and debug using the code examples you sent me. Compared to v37 that you used: 1) The IntegerSolver no longer creates subproblems that are difficult to solve (the way it did in your case). 2) The LinearSolver can now handle problem instances like the ones the IntegerSolver used to create 3) The ExpressionsBasedModel (in combination with the IntegerSolver) is now better at identifying when/if it doesn't need to call a solver at all. I've backported the entire org.ojalgo.optimisation.* package(s) to the Java7 branch at GitHub, and I've built and uploaded v37.1 to SourceForge. Please try this and report the results here, /Anders > On 28 jan 2015, at 14:55, Uli Schlachter <Uli...@In...> wrote: > > Am 28.01.2015 um 13:00 schrieb Anders Peterson: >> Have I understood this correct: You have a model with 2 variables and 2 inequality constraints that, at a specific branch-and-bound node, demonstrates the problem? > > Yeah, correctly. > > However, this model now demonstrates the problem without any branching at all. > >> From the output and your comments it seems clear that the problem is with the LinearSolver - it fails to discover/report that a subproblem is infeasible. >> >> The output contains this: "Switching to Phase2 with 1 artificial variable(s) still in the basis." >> >> ...and then I've noticed that you have not specified an objective function (any/all solutions are equally good). >> >> This combination could very well be something that ojAlgo fails to handle. I'll look in to this, but it has to be in a few days or so. > > Sure, no hurry. I just want to report my findings and hope that they will be useful to you. Feel free to ignore my problem until you have the time. > >> Have you tried specifying an objective function - preferably one that clearly favours some solutions over others? (x is better than y) > > Not yet. A quick experiment with various weights didn't change anything (I always got an invalid solution which was claimed to be OPTIMAL, but which solution I get changes with the weights). > > I'm now down to this: > > ExpressionsBasedModel model = new ExpressionsBasedModel(); > > model.addVariable(Variable.make("x").integer(true). > lower(1).upper(20).weight(1)); > model.addVariable(Variable.make("y").integer(true). > upper(-1).weight(-1)); > > Expression e = model.addExpression("inequality1"); > e.setLinearFactor(0, -10); > e.setLinearFactor(1, -199); > e.upper(-1); > > e = model.addExpression("inequality2"); > e.setLinearFactor(0, -10); > e.setLinearFactor(0, -10); > e.setLinearFactor(1, -200); > e.upper(-1); > > result = model.minimise(); > > > With the weights as in the code above, I even get a solution x=1, y=0, which contradicts y's upper limit of -1. With model.options.validate = true, ojAlgo notices some problem and the above system is unsolvable. > > Please note: > integer(true) on "y" is the key ingredient. If this variable isn't integer, ojAlgo correctly deduces "unsolvable". If both variables have ..integer(false), ojAlgo also deduces "unsolvable". If this variable is integer, ojAlgo claims to find a solution (but validate = true still makes it notice its error). > > So the OldIntegerSolver must somehow be involved with the problem as well, I just have no idea how. It must be more than just the relaxation, but what? > > Attached is again some small java program. Feel free to ignore it, but it contains the above code and tries to solve this once with model.options.validate = true and once with = false. The result in both cases is different. > > The results are the same with the latest git version of ojAlgo. > >> /Anders > > Cheers, > Uli > who can wait a week or two before looking at this again. :-) > >>> On 28 jan 2015, at 10:25, Uli Schlachter <Uli...@In...> wrote: >>> >>> Hi, >>> >>> I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: >>> >>> - I reduced the model used to: >>> >>> -10*x + -199*y <= -1 >>> -10*x + -200*y <= -1 >>> >>> This still shows the same behavior as the code from my first mail. >>> >>> - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: >>> >>> 1 <= x <= 20 >>> y <= -1 >>> >>> -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". >>> >>> - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) >>> >>> - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: >>> >>> if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { >>> // This should not be possible. There is a bug somewhere. >>> OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + >>> "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + >>> myKey.toString() + "\n" + >>> OldIntegerSolver.this.toString() +"\n" + >>> tmpModel.toString() +"\n"); >>> final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); >>> tmpDefaultSolver.solve(); >>> OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); >>> return false; >>> } >>> >>> - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". >>> >>> At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. >>> >>> Cheers & have a nice week, >>> Uli >>> >>> Am 27.01.2015 um 17:56 schrieb Anders Peterson: >>>> Most likely the rounding problem/numerical issue is with the LinearSolver. >>>> >>>> I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. >>>> >>>> To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. >>>> >>>> I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. >>>> >>>> If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. >>>> >>>> If you turn on solver debugging you'll get some info regarding what goes on: >>>> >>>> model.options.debug(LinearSolver.class); >>>> >>>> or >>>> >>>> model.options.debug(IntegerSolver.class); >>>> >>>> >>>> or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. >>>> >>>> >>>> /Anders >>>> >>>> >>>> >>>>> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >>>>> >>>>> Hi, >>>>> >>>>> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>>>>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >>>>> >>>>> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >>>>> with the latest development version and sadly my project cannot switch >>>>> from Java 7 to Java 8. >>>>> >>>>>> x = 21.0 ~ 21 >>>>>> y = -1.0 ~ -1 >>>>>> >>>>>> Is that what you want? >>>>> >>>>> x = 21 and y = -1 is indeed one of my desired solution. >>>>> >>>>>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>>>>> these are a bit sensitive and changing them is not generally >>>>> recommended, but he "integer" and "solution" number >>>>>> contexts should be relatively safe to tweak. >>>>> >>>>> I don't have much time right now, but I will look more closely into this >>>>> later. >>>>> >>>>> From what I understand right now, "solution" affects how the solution >>>>> is turned into a BigDecimal. However, I don't see how rounding >>>>> "19.999.." can get help me here, since the desired value would be 21. >>>>> >>>>> The member "integer" sounds more promising. I guess I want something >>>>> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >>>>> will experiment with this later. Thanks for the hint. >>>>> >>>>>> If you call minimise() rather than solve() does it make a difference? >>>>> >>>>> None that matters, but the values in the result change a little. >>>>> >>>>> solve(): >>>>> >>>>> x = 19.999999999999993 ~ 20 >>>>> y = -0.9950000000000006 ~ -1 >>>>> >>>>> minimise(): >>>>> >>>>> x = 20.00000000000000 ~ 20 >>>>> y = -0.99500000000000 ~ -1 >>>>> >>>>>> /Anders >>>>> >>>>> Thanks for looking into this. >>>>> Uli >>>>> >>>>>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>>>>> >>>>>>> Hi everyone, >>>>>>> >>>>>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>>>>> >>>>>>> Hopefully the program explains itself, but here is some more text: >>>>>>> >>>>>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>>>>> >>>>>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>>>>> >>>>>>> x = 19.999999999999993 ~ 20 >>>>>>> y = -0.9950000000000006 ~ -1 >>>>>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>>>>> at Solve.main(Solve.java:60) >>>>>>> >>>>>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>>>>> >>>>>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>>>>> >>>>>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>>>>> >>>>>>> Cheers, >>>>>>> Uli >>>>>>> -- >>>>>>> - Buck, when, exactly, did you lose your mind? >>>>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>>>> An ugly pineapple... But I loved her. >>>>>>> <Solve.java>------------------------------------------------------------------------------ >>>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>>> hub for all things parallel software development, from weekly thought >>>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>>>>> ojAlgo-user mailing list >>>>>>> ojA...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>> >>>>>> >>>>>> ------------------------------------------------------------------------------ >>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>> hub for all things parallel software development, from weekly thought >>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>>> _______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>>> >>>>> >>>>> >>>>> -- >>>>> - Buck, when, exactly, did you lose your mind? >>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>> An ugly pineapple... But I loved her. >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>> hub for all things parallel software development, from weekly thought >>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>> >>> >>> -- >>> - Buck, when, exactly, did you lose your mind? >>> - Three months ago. I woke up one morning married to a pineapple. >>> An ugly pineapple... But I loved her. >>> <Solve.java><output.txt>------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> > > > -- > - Buck, when, exactly, did you lose your mind? > - Three months ago. I woke up one morning married to a pineapple. > An ugly pineapple... But I loved her. > <Solve.java>------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2015-01-31 14:12:12
|
The MarkowitzModel class was recently updated. The algorithm used when you set a "target variance" was improved, and the algorithm used with a "target return" completely rewritten. Both cases now function roughly the same way. There was a problem with the "target variance" algorithm in that it would not always reach the target although possible.This has been fixed. The "target return" algorithm is now slightly slower than before, but more robust. If a target is unreachable the algorithm will still look for a solution as good as possible. Previously the algorithm would fail if the target was unreachable. /Anders > On 8 dec 2014, at 08:32, Anders Peterson wrote: > > I don't have detailed knowledge of Apache Common Maths or Brent's method, but I understand roughly what you've done. My guess is that with the changes I checked in the other day you don't need this. ;-) How many iterations does the BrentSolver typically do? The updated version of ojAlgo's MarkowitzModel zooms in on the target variance in about 20 iterations. Is your Brent-solver better than that? > > > /Anders > > >> Hi Anders, >> >> I am now happy with my new implementation of the MarkowitzModel.java class. It is, however, messy in that I now use the Apache Common Maths library and I would prefer to use pure ojAlgo but quite simply, I did the following: >> >> 1. Declared: >> >> import org.apache.commons.math3.analysis.UnivariateFunction; >> import org.apache.commons.math3.analysis.solvers.BrentSolver; >> >> 2. Made my class implement the UnivariateFunction interface. >> >> 3. Instead of using the getWeights() method of the MarkowitzModel.java class having previously set the target variance using the setTargetVariance() method, I used the following code: >> >> BrentSolver brentSolver = new BrentSolver(); >> brentSolver.solve(100, this , minApache, maxApache, (maxApache-minApache)/2); >> where minApache = 0.0 and maxApache=10,000.00 >> >> 4. I implemented the method public double value(double x) for the BrentSolver class and used the set x to be the riskAversion and made the method return: >> the portfolio variance (derived from the calculatePortfolioVariance() method) minus the target variance. >> >> Please let me know if that is not clear. I am looking forward to testing your latest version against this implementation tomorrow. >> >> Regards, >> >> >> >> -----Original Message----- >> Sent: 07 December 2014 13:15 >> To: 'Anders Peterson' >> Cc: ojAlgo ojAlgo >> Subject: RE: MarkowitzModel.java >> >> Hi Anders, >> >> Sorry for not replying to your last email but I have been busy doing what you wrote and I have been coming in this weekend to test it. Thanks for the update and I will test this against my new implementation. I will write more once I am comfortable with my new implementation (hopefully today). >> >> Regards, >> >> >> -----Original Message----- >> Sent: 06 December 2014 16:22 >> Cc: ojAlgo ojAlgo >> Subject: Re: MarkowitzModel.java >> >> I had a look at that algorithm and found some obvious improvements. I've updated the source code repositories and uploaded snapshot v37.10 to SourceForge. >> >> You'll find it works better now, but I still recommend not to set a target variance or return. >> >> /Anders >> >> >>> On 2 dec 2014, at 23:06, Anders Peterson wrote: >>> >>> Hi, >>> >>> That little algorithm in the MarkowitzModel to handle the quadratic constraint caused by setting a target variance was a temporary solution, and as such it was not thoroughly tuned. The real solution is to develop an optimisation solver that can handle quadratic constraints. I aim to do this. >>> >>> I prefer not to make the parameters you mention publicly adjustable. (I want to get rid of them.) Maybe you can convince me to do it anyway, but let me offer some alternatives: >>> >>> 1) If you can supply better values for those parameters I'd be happy to change the code. >>> >>> 2) I strongly recommend you to try NOT setting a target variance or target return. Instead you simply adjust the risk aversion factor. You can code a master algorithm that solves a sequence of subproblems (different risk aversions) to end up with any feasible risk or return. That's what MarkowitzModel does when you specify a target variance. >>> >>> 3) Even if you decide to continue setting the target variance you can try also adjusting the risk aversion. It is a factor in the algorithm just like "tmpIterCount" and "_0_000005". >>> >>> >>> /Anders >>> >>> >>>> On 2 dec 2014, at 15:39, wrote: >>>> >>>> Hi anders, >>>> >>>> First of all, let me say that I really like ojAlgo so thank you for making it! I do, however, think that you should make tmpIterCount and _0_000005 variables fields (with getters and setters) in the MarkowitzModel.java class. We are finding that we get suboptimal solutions with the hard-coded limit of 20 iterations in a mean variance optimisation (solving for the highest return given a target variance). We are now testing it (against our own Python model) with a limit of 100. >>>> >>>> Please let me know what you think when you get a chance. >>>> >>>> Regards, |
From: Uli S. <Uli...@In...> - 2015-01-28 13:55:52
|
Am 28.01.2015 um 13:00 schrieb Anders Peterson: > Have I understood this correct: You have a model with 2 variables and 2 inequality constraints that, at a specific branch-and-bound node, demonstrates the problem? Yeah, correctly. However, this model now demonstrates the problem without any branching at all. >From the output and your comments it seems clear that the problem is with the LinearSolver - it fails to discover/report that a subproblem is infeasible. > > The output contains this: "Switching to Phase2 with 1 artificial variable(s) still in the basis." > > ...and then I've noticed that you have not specified an objective function (any/all solutions are equally good). > > This combination could very well be something that ojAlgo fails to handle. I'll look in to this, but it has to be in a few days or so. Sure, no hurry. I just want to report my findings and hope that they will be useful to you. Feel free to ignore my problem until you have the time. > Have you tried specifying an objective function - preferably one that clearly favours some solutions over others? (x is better than y) Not yet. A quick experiment with various weights didn't change anything (I always got an invalid solution which was claimed to be OPTIMAL, but which solution I get changes with the weights). I'm now down to this: ExpressionsBasedModel model = new ExpressionsBasedModel(); model.addVariable(Variable.make("x").integer(true). lower(1).upper(20).weight(1)); model.addVariable(Variable.make("y").integer(true). upper(-1).weight(-1)); Expression e = model.addExpression("inequality1"); e.setLinearFactor(0, -10); e.setLinearFactor(1, -199); e.upper(-1); e = model.addExpression("inequality2"); e.setLinearFactor(0, -10); e.setLinearFactor(0, -10); e.setLinearFactor(1, -200); e.upper(-1); result = model.minimise(); With the weights as in the code above, I even get a solution x=1, y=0, which contradicts y's upper limit of -1. With model.options.validate = true, ojAlgo notices some problem and the above system is unsolvable. Please note: integer(true) on "y" is the key ingredient. If this variable isn't integer, ojAlgo correctly deduces "unsolvable". If both variables have .integer(false), ojAlgo also deduces "unsolvable". If this variable is integer, ojAlgo claims to find a solution (but validate = true still makes it notice its error). So the OldIntegerSolver must somehow be involved with the problem as well, I just have no idea how. It must be more than just the relaxation, but what? Attached is again some small java program. Feel free to ignore it, but it contains the above code and tries to solve this once with model.options.validate = true and once with = false. The result in both cases is different. The results are the same with the latest git version of ojAlgo. > /Anders Cheers, Uli who can wait a week or two before looking at this again. :-) >> On 28 jan 2015, at 10:25, Uli Schlachter <Uli...@In...> wrote: >> >> Hi, >> >> I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: >> >> - I reduced the model used to: >> >> -10*x + -199*y <= -1 >> -10*x + -200*y <= -1 >> >> This still shows the same behavior as the code from my first mail. >> >> - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: >> >> 1 <= x <= 20 >> y <= -1 >> >> -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". >> >> - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) >> >> - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: >> >> if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { >> // This should not be possible. There is a bug somewhere. >> OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + >> "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + >> myKey.toString() + "\n" + >> OldIntegerSolver.this.toString() +"\n" + >> tmpModel.toString() +"\n"); >> final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); >> tmpDefaultSolver.solve(); >> OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); >> return false; >> } >> >> - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". >> >> At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. >> >> Cheers & have a nice week, >> Uli >> >> Am 27.01.2015 um 17:56 schrieb Anders Peterson: >>> Most likely the rounding problem/numerical issue is with the LinearSolver. >>> >>> I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. >>> >>> To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. >>> >>> I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. >>> >>> If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. >>> >>> If you turn on solver debugging you'll get some info regarding what goes on: >>> >>> model.options.debug(LinearSolver.class); >>> >>> or >>> >>> model.options.debug(IntegerSolver.class); >>> >>> >>> or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. >>> >>> >>> /Anders >>> >>> >>> >>>> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >>>> >>>> Hi, >>>> >>>> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>>>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >>>> >>>> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >>>> with the latest development version and sadly my project cannot switch >>>> from Java 7 to Java 8. >>>> >>>>> x = 21.0 ~ 21 >>>>> y = -1.0 ~ -1 >>>>> >>>>> Is that what you want? >>>> >>>> x = 21 and y = -1 is indeed one of my desired solution. >>>> >>>>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>>>> these are a bit sensitive and changing them is not generally >>>> recommended, but he "integer" and "solution" number >>>>> contexts should be relatively safe to tweak. >>>> >>>> I don't have much time right now, but I will look more closely into this >>>> later. >>>> >>>> From what I understand right now, "solution" affects how the solution >>>> is turned into a BigDecimal. However, I don't see how rounding >>>> "19.999.." can get help me here, since the desired value would be 21. >>>> >>>> The member "integer" sounds more promising. I guess I want something >>>> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >>>> will experiment with this later. Thanks for the hint. >>>> >>>>> If you call minimise() rather than solve() does it make a difference? >>>> >>>> None that matters, but the values in the result change a little. >>>> >>>> solve(): >>>> >>>> x = 19.999999999999993 ~ 20 >>>> y = -0.9950000000000006 ~ -1 >>>> >>>> minimise(): >>>> >>>> x = 20.00000000000000 ~ 20 >>>> y = -0.99500000000000 ~ -1 >>>> >>>>> /Anders >>>> >>>> Thanks for looking into this. >>>> Uli >>>> >>>>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>>>> >>>>>> Hi everyone, >>>>>> >>>>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>>>> >>>>>> Hopefully the program explains itself, but here is some more text: >>>>>> >>>>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>>>> >>>>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>>>> >>>>>> x = 19.999999999999993 ~ 20 >>>>>> y = -0.9950000000000006 ~ -1 >>>>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>>>> at Solve.main(Solve.java:60) >>>>>> >>>>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>>>> >>>>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>>>> >>>>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>>>> >>>>>> Cheers, >>>>>> Uli >>>>>> -- >>>>>> - Buck, when, exactly, did you lose your mind? >>>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>>> An ugly pineapple... But I loved her. >>>>>> <Solve.java>------------------------------------------------------------------------------ >>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>> hub for all things parallel software development, from weekly thought >>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>> hub for all things parallel software development, from weekly thought >>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>> >>>> >>>> -- >>>> - Buck, when, exactly, did you lose your mind? >>>> - Three months ago. I woke up one morning married to a pineapple. >>>> An ugly pineapple... But I loved her. >>>> >>>> ------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >>> ------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/ >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >> >> >> -- >> - Buck, when, exactly, did you lose your mind? >> - Three months ago. I woke up one morning married to a pineapple. >> An ugly pineapple... But I loved her. >> <Solve.java><output.txt>------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > -- - Buck, when, exactly, did you lose your mind? - Three months ago. I woke up one morning married to a pineapple. An ugly pineapple... But I loved her. |
From: Anders P. <an...@op...> - 2015-01-28 12:30:00
|
Try modifying model.options.objective it is what determines when to switch to Phase2. /Anders > On 28 jan 2015, at 13:00, Anders Peterson <an...@op...> wrote: > > Have I understood this correct: You have a model with 2 variables and 2 inequality constraints that, at a specific branch-and-bound node, demonstrates the problem? > > From the output and your comments it seems clear that the problem is with the LinearSolver - it fails to discover/report that a subproblem is infeasible. > > The output contains this: "Switching to Phase2 with 1 artificial variable(s) still in the basis." > > ....and then I've noticed that you have not specified an objective function (any/all solutions are equally good). > > This combination could very well be something that ojAlgo fails to handle. I'll look in to this, but it has to be in a few days or so. > > Have you tried specifying an objective function - preferably one that clearly favours some solutions over others? (x is better than y) > > > /Anders > > > >> On 28 jan 2015, at 10:25, Uli Schlachter <Uli...@In...> wrote: >> >> Hi, >> >> I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: >> >> - I reduced the model used to: >> >> -10*x + -199*y <= -1 >> -10*x + -200*y <= -1 >> >> This still shows the same behavior as the code from my first mail. >> >> - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: >> >> 1 <= x <= 20 >> y <= -1 >> >> -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". >> >> - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) >> >> - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: >> >> if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { >> // This should not be possible. There is a bug somewhere. >> OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + >> "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + >> myKey.toString() + "\n" + >> OldIntegerSolver.this.toString() +"\n" + >> tmpModel.toString() +"\n"); >> final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); >> tmpDefaultSolver.solve(); >> OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); >> return false; >> } >> >> - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". >> >> At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. >> >> Cheers & have a nice week, >> Uli >> >> Am 27.01.2015 um 17:56 schrieb Anders Peterson: >>> Most likely the rounding problem/numerical issue is with the LinearSolver. >>> >>> I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. >>> >>> To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. >>> >>> I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. >>> >>> If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. >>> >>> If you turn on solver debugging you'll get some info regarding what goes on: >>> >>> model.options.debug(LinearSolver.class); >>> >>> or >>> >>> model.options.debug(IntegerSolver.class); >>> >>> >>> or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. >>> >>> >>> /Anders >>> >>> >>> >>>> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >>>> >>>> Hi, >>>> >>>> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>>>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >>>> >>>> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >>>> with the latest development version and sadly my project cannot switch >>>> from Java 7 to Java 8. >>>> >>>>> x = 21.0 ~ 21 >>>>> y = -1.0 ~ -1 >>>>> >>>>> Is that what you want? >>>> >>>> x = 21 and y = -1 is indeed one of my desired solution. >>>> >>>>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>>>> these are a bit sensitive and changing them is not generally >>>> recommended, but he "integer" and "solution" number >>>>> contexts should be relatively safe to tweak. >>>> >>>> I don't have much time right now, but I will look more closely into this >>>> later. >>>> >>>> From what I understand right now, "solution" affects how the solution >>>> is turned into a BigDecimal. However, I don't see how rounding >>>> "19.999.." can get help me here, since the desired value would be 21. >>>> >>>> The member "integer" sounds more promising. I guess I want something >>>> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >>>> will experiment with this later. Thanks for the hint. >>>> >>>>> If you call minimise() rather than solve() does it make a difference? >>>> >>>> None that matters, but the values in the result change a little. >>>> >>>> solve(): >>>> >>>> x = 19.999999999999993 ~ 20 >>>> y = -0.9950000000000006 ~ -1 >>>> >>>> minimise(): >>>> >>>> x = 20.00000000000000 ~ 20 >>>> y = -0.99500000000000 ~ -1 >>>> >>>>> /Anders >>>> >>>> Thanks for looking into this. >>>> Uli >>>> >>>>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>>>> >>>>>> Hi everyone, >>>>>> >>>>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>>>> >>>>>> Hopefully the program explains itself, but here is some more text: >>>>>> >>>>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>>>> >>>>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>>>> >>>>>> x = 19.999999999999993 ~ 20 >>>>>> y = -0.9950000000000006 ~ -1 >>>>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>>>> at Solve.main(Solve.java:60) >>>>>> >>>>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>>>> >>>>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>>>> >>>>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>>>> >>>>>> Cheers, >>>>>> Uli >>>>>> -- >>>>>> - Buck, when, exactly, did you lose your mind? >>>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>>> An ugly pineapple... But I loved her. >>>>>> <Solve.java>------------------------------------------------------------------------------ >>>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>>> hub for all things parallel software development, from weekly thought >>>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>>>> ojAlgo-user mailing list >>>>>> ojA...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>> hub for all things parallel software development, from weekly thought >>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>>> _______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>>> >>>> >>>> >>>> -- >>>> - Buck, when, exactly, did you lose your mind? >>>> - Three months ago. I woke up one morning married to a pineapple. >>>> An ugly pineapple... But I loved her. >>>> >>>> ------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >>> ------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/ >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >> >> >> -- >> - Buck, when, exactly, did you lose your mind? >> - Three months ago. I woke up one morning married to a pineapple. >> An ugly pineapple... But I loved her. >> <Solve.java><output.txt>------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Anders P. <an...@op...> - 2015-01-28 12:00:28
|
Have I understood this correct: You have a model with 2 variables and 2 inequality constraints that, at a specific branch-and-bound node, demonstrates the problem? From the output and your comments it seems clear that the problem is with the LinearSolver - it fails to discover/report that a subproblem is infeasible. The output contains this: "Switching to Phase2 with 1 artificial variable(s) still in the basis." ...and then I've noticed that you have not specified an objective function (any/all solutions are equally good). This combination could very well be something that ojAlgo fails to handle. I'll look in to this, but it has to be in a few days or so. Have you tried specifying an objective function - preferably one that clearly favours some solutions over others? (x is better than y) /Anders > On 28 jan 2015, at 10:25, Uli Schlachter <Uli...@In...> wrote: > > Hi, > > I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: > > - I reduced the model used to: > > -10*x + -199*y <= -1 > -10*x + -200*y <= -1 > > This still shows the same behavior as the code from my first mail. > > - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: > > 1 <= x <= 20 > y <= -1 > > -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". > > - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) > > - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: > > if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { > // This should not be possible. There is a bug somewhere. > OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + > "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + > myKey.toString() + "\n" + > OldIntegerSolver.this.toString() +"\n" + > tmpModel.toString() +"\n"); > final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); > tmpDefaultSolver.solve(); > OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); > return false; > } > > - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". > > At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. > > Cheers & have a nice week, > Uli > > Am 27.01.2015 um 17:56 schrieb Anders Peterson: >> Most likely the rounding problem/numerical issue is with the LinearSolver. >> >> I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. >> >> To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. >> >> I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. >> >> If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. >> >> If you turn on solver debugging you'll get some info regarding what goes on: >> >> model.options.debug(LinearSolver.class); >> >> or >> >> model.options.debug(IntegerSolver.class); >> >> >> or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. >> >> >> /Anders >> >> >> >>> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >>> >>> Hi, >>> >>> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >>> >>> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >>> with the latest development version and sadly my project cannot switch >>> from Java 7 to Java 8. >>> >>>> x = 21.0 ~ 21 >>>> y = -1.0 ~ -1 >>>> >>>> Is that what you want? >>> >>> x = 21 and y = -1 is indeed one of my desired solution. >>> >>>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>>> these are a bit sensitive and changing them is not generally >>> recommended, but he "integer" and "solution" number >>>> contexts should be relatively safe to tweak. >>> >>> I don't have much time right now, but I will look more closely into this >>> later. >>> >>> From what I understand right now, "solution" affects how the solution >>> is turned into a BigDecimal. However, I don't see how rounding >>> "19.999.." can get help me here, since the desired value would be 21. >>> >>> The member "integer" sounds more promising. I guess I want something >>> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >>> will experiment with this later. Thanks for the hint. >>> >>>> If you call minimise() rather than solve() does it make a difference? >>> >>> None that matters, but the values in the result change a little. >>> >>> solve(): >>> >>> x = 19.999999999999993 ~ 20 >>> y = -0.9950000000000006 ~ -1 >>> >>> minimise(): >>> >>> x = 20.00000000000000 ~ 20 >>> y = -0.99500000000000 ~ -1 >>> >>>> /Anders >>> >>> Thanks for looking into this. >>> Uli >>> >>>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>>> >>>>> Hi everyone, >>>>> >>>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>>> >>>>> Hopefully the program explains itself, but here is some more text: >>>>> >>>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>>> >>>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>>> >>>>> x = 19.999999999999993 ~ 20 >>>>> y = -0.9950000000000006 ~ -1 >>>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>>> at Solve.main(Solve.java:60) >>>>> >>>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>>> >>>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>>> >>>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>>> >>>>> Cheers, >>>>> Uli >>>>> -- >>>>> - Buck, when, exactly, did you lose your mind? >>>>> - Three months ago. I woke up one morning married to a pineapple. >>>>> An ugly pineapple... But I loved her. >>>>> <Solve.java>------------------------------------------------------------------------------ >>>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>>> hub for all things parallel software development, from weekly thought >>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>>> ojAlgo-user mailing list >>>>> ojA...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/ >>>> _______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>>> >>> >>> >>> -- >>> - Buck, when, exactly, did you lose your mind? >>> - Three months ago. I woke up one morning married to a pineapple. >>> An ugly pineapple... But I loved her. >>> >>> ------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/ >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> > > > -- > - Buck, when, exactly, did you lose your mind? > - Three months ago. I woke up one morning married to a pineapple. > An ugly pineapple... But I loved her. > <Solve.java><output.txt>------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |
From: Uli S. <Uli...@In...> - 2015-01-28 09:25:34
|
Hi, I tried looking into this, but I'm not familiar enough with ojAlgo's internals, I guess. Attached is what I ended up with: - I reduced the model used to: -10*x + -199*y <= -1 -10*x + -200*y <= -1 This still shows the same behavior as the code from my first mail. - Thanks to your hint with model.options.debug(), I added the following which is what the Branch&Bounde Node where "something goes wrong" uses: 1 <= x <= 20 y <= -1 -This makes the model unsolvable, but with model.options.validate = true, ojAlgo still notices that "something is wrong". - Also this has the nice side effect that no branching happens anymore and thus no non-determinism due to threads. (More readable debug output!) - In OldIntegerSolver, there is some code that is commented out which prints more information in case validation fails. I ended up with this: if (OldIntegerSolver.this.options.validate && !tmpModel.validate(tmpResult)) { // This should not be possible. There is a bug somewhere. OldIntegerSolver.this.debug("!!!!!!!\n!!!!!!!\n" + "Node solution marked as OPTIMAL, but is actually INVALID/INFEASIBLE/FAILED. Stop this branch!\n" + myKey.toString() + "\n" + OldIntegerSolver.this.toString() +"\n" + tmpModel.toString() +"\n"); final GenericSolver tmpDefaultSolver = tmpModel.getDefaultSolver(); tmpDefaultSolver.solve(); OldIntegerSolver.this.debug(tmpDefaultSolver.toString()); return false; } - The output produced by model.options.debug(LinearSolver.class); from this is attached. Please note that the above code calls solve() again on the model. I checked that this second run produces the same debug output and removed it from the log file. The position is marked with "[SNIP...]". At this point I don't know how to continue, but hopefully this helps you in figuring out things when you have the time. Cheers & have a nice week, Uli Am 27.01.2015 um 17:56 schrieb Anders Peterson: > Most likely the rounding problem/numerical issue is with the LinearSolver. > > I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. > > To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. > > I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. > > If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. > > If you turn on solver debugging you'll get some info regarding what goes on: > > model.options.debug(LinearSolver.class); > > or > > model.options.debug(IntegerSolver.class); > > > or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. > > > /Anders > > > >> On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: >> >> Hi, >> >> Am 27.01.2015 um 12:23 schrieb Anders Peterson: >>> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; >> >> Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try >> with the latest development version and sadly my project cannot switch >> from Java 7 to Java 8. >> >>> x = 21.0 ~ 21 >>> y = -1.0 ~ -1 >>> >>> Is that what you want? >> >> x = 21 and y = -1 is indeed one of my desired solution. >> >>> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >>> these are a bit sensitive and changing them is not generally >> recommended, but he "integer" and "solution" number >>> contexts should be relatively safe to tweak. >> >> I don't have much time right now, but I will look more closely into this >> later. >> >> From what I understand right now, "solution" affects how the solution >> is turned into a BigDecimal. However, I don't see how rounding >> "19.999.." can get help me here, since the desired value would be 21. >> >> The member "integer" sounds more promising. I guess I want something >> like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I >> will experiment with this later. Thanks for the hint. >> >>> If you call minimise() rather than solve() does it make a difference? >> >> None that matters, but the values in the result change a little. >> >> solve(): >> >> x = 19.999999999999993 ~ 20 >> y = -0.9950000000000006 ~ -1 >> >> minimise(): >> >> x = 20.00000000000000 ~ 20 >> y = -0.99500000000000 ~ -1 >> >>> /Anders >> >> Thanks for looking into this. >> Uli >> >>>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>>> >>>> Hi everyone, >>>> >>>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>>> >>>> Hopefully the program explains itself, but here is some more text: >>>> >>>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>>> >>>> However, this fails since the solution calculated doesn't solve all inequalities: >>>> >>>> x = 19.999999999999993 ~ 20 >>>> y = -0.9950000000000006 ~ -1 >>>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>>> at Solve.main(Solve.java:60) >>>> >>>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>>> >>>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>>> >>>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>>> >>>> Cheers, >>>> Uli >>>> -- >>>> - Buck, when, exactly, did you lose your mind? >>>> - Three months ago. I woke up one morning married to a pineapple. >>>> An ugly pineapple... But I loved her. >>>> <Solve.java>------------------------------------------------------------------------------ >>>> Dive into the World of Parallel Programming. The Go Parallel Website, >>>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>>> hub for all things parallel software development, from weekly thought >>>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>>> ojAlgo-user mailing list >>>> ojA...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >>> >>> ------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/ >>> _______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >>> >> >> >> -- >> - Buck, when, exactly, did you lose your mind? >> - Three months ago. I woke up one morning married to a pineapple. >> An ugly pineapple... But I loved her. >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > -- - Buck, when, exactly, did you lose your mind? - Three months ago. I woke up one morning married to a pineapple. An ugly pineapple... But I loved her. |
From: Anders P. <an...@op...> - 2015-01-27 16:56:14
|
Most likely the rounding problem/numerical issue is with the LinearSolver. I recently discovered (and fixed) a problem that would cause the ExpressionsBasedModel to call a solver even though it had effectively already determined a solution. This is something that could potentially kick in very often while using the IntegerSolver. The problem is I can't remember exactly what the code change was. It was just something I stumbled upon while working on something else. Did a quick compare with v37 but didn't see it. To summarize what I believe. The actual "rounding issue" is with the LinearSolver, and that problem is still there in the latest development version. The reason I get a different behavior/solution is because the LinearSolver is never invoked for some subproblems. The solution is determined completely using BigDecimal-logic in the ExpressionsBasedModel class. I will not have time to look further at this during the coming week. Eventually I will construct a few test cases from the model you sent me and debug the problem, but I don't have a quick fix. If you want to look at this yourself you can either try to figure out what goes wrong with the LinearSolver or look for that ExpressionsBasedModel change, or both. If you turn on solver debugging you'll get some info regarding what goes on: model.options.debug(LinearSolver.class); or model.options.debug(IntegerSolver.class); or set breakpoints and debug the code in ExpressionsBasedModel that presolve and determine which solver to call. /Anders > On 27 jan 2015, at 14:10, Uli Schlachter <Uli...@In...> wrote: > > Hi, > > Am 27.01.2015 um 12:23 schrieb Anders Peterson: >> Running your program with the latest development version of ojAlgo (requires Java 8) I get this output and no exceptions; > > Sorry that I didn't mention it, but I am using ojAlgo 37. I did not try > with the latest development version and sadly my project cannot switch > from Java 7 to Java 8. > >> x = 21.0 ~ 21 >> y = -1.0 ~ -1 >> >> Is that what you want? > > x = 21 and y = -1 is indeed one of my desired solution. > >> There are a number of configurable options in ExpressionsBasedModel.options that control accuracy and rounding. Some of >> these are a bit sensitive and changing them is not generally > recommended, but he "integer" and "solution" number >> contexts should be relatively safe to tweak. > > I don't have much time right now, but I will look more closely into this > later. > > From what I understand right now, "solution" affects how the solution > is turned into a BigDecimal. However, I don't see how rounding > "19.999.." can get help me here, since the desired value would be 21. > > The member "integer" sounds more promising. I guess I want something > like a new NumberContext(largish-value-e.g.-10, RoundingMode.HALF_UP). I > will experiment with this later. Thanks for the hint. > >> If you call minimise() rather than solve() does it make a difference? > > None that matters, but the values in the result change a little. > > solve(): > > x = 19.999999999999993 ~ 20 > y = -0.9950000000000006 ~ -1 > > minimise(): > > x = 20.00000000000000 ~ 20 > y = -0.99500000000000 ~ -1 > >> /Anders > > Thanks for looking into this. > Uli > >>> On 27 jan 2015, at 10:10, Uli Schlachter <Uli...@In...> wrote: >>> >>> Hi everyone, >>> >>> the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? >>> >>> Hopefully the program explains itself, but here is some more text: >>> >>> The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. >>> >>> However, this fails since the solution calculated doesn't solve all inequalities: >>> >>> x = 19.999999999999993 ~ 20 >>> y = -0.9950000000000006 ~ -1 >>> Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) >>> at Solve.main(Solve.java:60) >>> >>> The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". >>> >>> Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. >>> >>> Obviously, this seems to be a rounding issue. Is there anything that can be done about it? >>> >>> Cheers, >>> Uli >>> -- >>> - Buck, when, exactly, did you lose your mind? >>> - Three months ago. I woke up one morning married to a pineapple. >>> An ugly pineapple... But I loved her. >>> <Solve.java>------------------------------------------------------------------------------ >>> Dive into the World of Parallel Programming. The Go Parallel Website, >>> sponsored by Intel and developed in partnership with Slashdot Media, is your >>> hub for all things parallel software development, from weekly thought >>> leadership blogs to news, videos, case studies, tutorials and more. Take a >>> look and join the conversation now. http://goparallel.sourceforge.net/_______________________________________________ >>> ojAlgo-user mailing list >>> ojA...@li... >>> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming. The Go Parallel Website, >> sponsored by Intel and developed in partnership with Slashdot Media, is your >> hub for all things parallel software development, from weekly thought >> leadership blogs to news, videos, case studies, tutorials and more. Take a >> look and join the conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user >> > > > -- > - Buck, when, exactly, did you lose your mind? > - Three months ago. I woke up one morning married to a pineapple. > An ugly pineapple... But I loved her. > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |