[ 
https://issues.apache.org/jira/browse/MATH-1550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17161452#comment-17161452
 ] 

Mohammad Rezaei commented on MATH-1550:
---------------------------------------

May I suggest we keep the immutability topic in this thread and leave 1549 for 
the fix?
{quote} over the long haul, we've been trying to modify all the library's codes 
towards immutability
{quote}
Some of the core data structures provided by the math library are mutable by 
design. These include the vectors that are also used in Simplex. Unlike 
SimplexTableau, those classes are meant for public usage and there is 
essentially no hope to make them immutable any more. I don't think that's a bad 
thing. There are many algorithms that benefit from mutable data structures, 
especially when said data structures are bulky and algorithms rely on changing 
selected members.
  
{quote} There is a balance to be found (copying in Java is not nearly as bad as 
in C and sometimes an extra copy even provides a performance boost!).
{quote}
I agree. The point, however, is *_balance_*. All immutable is just as bad as 
all mutable. There are many things that immutability can't do. Did you know, no 
one has ever invented an immutable O(1) hash structure? On the other hand, O(1) 
mutable hash structures have been in use for over 40 years in real production 
code.

Sorry about the long philosophizing. Let's get back to the issue at hand.

Adding a final decorator to the tableau field doesn't really do much, because 
the matrix is internally modified (see the performRowOperation method). For 
this class, none of this matters because it's not a public class and it's only 
ever instantiated in a method (so it's effectively thread local).

When I was researching this issue, I found out that there are standard suites 
of tests for linear solvers. These are used to compare various implementations, 
including commercial offerings. I was honestly surprised to see how sparse the 
testing for SimplexSolver is. So here is what I suggest: if you really want to 
explore making the matrix immutable, first implement these tests for both 
correctness and performance.

Here are some standard tests (these are encoded in 
[https://en.wikipedia.org/wiki/MPS_(format]) ):
 [http://www.numerical.rl.ac.uk/cute/netlib.html] or 
[https://www.netlib.org/lp/data/index.html]
 [https://www.netlib.org/lp/infeas/index.html]
 
[http://www.gamsworld.org/performance/plib/credits.htm#Mittelmann%20H.%20-%20LP%20Models]

and there is more (see anything labeled "LP" here: 
[http://www.gamsworld.org/performance/plib/credits.htm]). It might look like a 
lot, but it's actually just a matter of writing a single parser and looping 
through all the test cases.

 

 

 

> SimplexTableau (linear programming)
> -----------------------------------
>
>                 Key: MATH-1550
>                 URL: https://issues.apache.org/jira/browse/MATH-1550
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.6.1
>            Reporter: Gilles Sadowski
>            Priority: Minor
>              Labels: design
>             Fix For: 4.0, 4.X
>
>
> Class {{SimplexTableau}} is package private and does not seem designed for 
> inheritance, but it contains "protected" methods.
> There are several instance fields that should preferably be made "final" (for 
> thread safety). It seems that to do this, some design changes are necessary 
> (a.o. the relationship with {{SimplexSolver}} should be clarified).
>  
> {{SimplexSolver}} also contains a protected method ({{solvePhase1}}) that is 
> not documented for inheritance.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to