Giter Club home page Giter Club logo

ojalgo's People

Contributors

alexlukas avatar alf239 avatar andrievskya avatar apete avatar baracil avatar chang-chao avatar dependabot[bot] avatar esarbe avatar lostnut avatar programmer-magnus avatar sashee avatar sudo-jaa avatar thibaultleouay avatar younes-abouelnagah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ojalgo's Issues

Re-use eigenvalue/-vector storage arrays in RawEigenvalue.doDecomposeGeneral when applicable

Currently, Vt, e, and d are created as new instances for every call to RawEigenvalue.doComposeGeneral:
https://github.com/optimatika/ojAlgo/blob/master/src/org/ojalgo/matrix/decomposition/RawEigenvalue.java#L1060-L1062
Creating new instances could be avoided by re-using these objects when applicable, i.e. matrix dimensions do not change.
As far as I can tell that would require an additional member variable to store the double[][] that is referenced by Vt in doDecomposeGeneral.

ERC Portfolio optimization

Hi,

I am currently trying to use this library to solve ERC portfolio optimization but I am not sure that this library is able to do that.

The function I have to minimize is on the top of the page 7 at http://thierry-roncalli.com/download/erc.pdf.

Could you please tell me if ojAlgo is able to resolve this quadratic optimization problem ?

Thanks for your help.

Problem with the pom files at The Central Repository

There is an extra/incorrect character at the very beginning of the pom files uploaded to The Central Repository. Maven seems to accept this and The Central Repository validation procedure this not catch this problem - that why the mistake wasn't caught in time.

Many parsers cannot handle those pom:s. Most browsers cannot display them and Gradle users have reported problems depending on ojAlgo.

Released files cannot be modified. We will have to release new versions with the problem fixed.

Missing function to delete a constraint?

Hi, im integrating this solver to my project. I managed to delete bounds of a variable but constraints what are created with
Expression c = model.addExpression("c").level(value);
c.setLinearFactors(model.getVariables(), foobar);

i cant delete completely from the model, where the counter of expressions decrease too.
I tried setting the levels null, like deleting bounds for variable, but they still remain in the model, even the bounds are no more visible. So am I doing something wrong or does this function doesnt exist?

Regards
alper

Quadratic Objective Function.

Hello,

First many thanks for your great library.

I have a question about usage of the library, I'm not sure if it's an issue in the library or my problem is not well defined.

The situation :

From one side I have a list of Customer. (CUSTOMER_1, CUSTOMER_2, CUSTOMER_3,....)
From an other side I have distinct Type (version) of product (PRODUCT_TYPE_1,PRODUCT_TYPE_2, ...)

I create all available links between Customer and Product Type.
Each link is a variable. It's represent the allocation of Product type X to the Customer X.

I create constraints for Customer level. (Ex: CUSTOMER_1 need <= 40_000)

  • The sum of all variables linked to CUSTOMER_1 <= 40_000

I create constraints for Product level. (Ex: PRODUCT_TYPE_1 <= 50_000)

  • The sum of all variables linked to PRODUCT_TYPE_1 <= 50_000

I try to maximize the allocation :
Max of (the sum of all variables)

But on other hand, I try to be fair, I try to split proportionally between customers:

For that, I compute the global ratio (stockTotal/demandTotal) and compute the squared error between the allocation and the global ratio.
I create for each Customer a Variable error and an expression to compute the error:

Error + Sum(Variables Customer X) / Demand Customer X = Stock Total / Demand Total

And I remove the Squared of each errors in the objective function.

The result I have with the OjAlgo Library is strange. The result can be different between run with the same data input.

Do you think, my problem is solvable by your library or not ? If yes, what I'm doing wrong ?
Or is it possible there is a bug in OjAlgo library ?

My Test file is available here : https://github.com/dmex38/JavaExample/blob/master/OJAlgoTest

Sometime I have this result :

OPTIMAL 49998.797722288284 @ [40000.0, 10000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.425287356322, -0.174712643678, -0.574712643678, -0.574712643678, -0.574712643678]

0 <= CUSTOMER_1|PRODUCT_TYPE_1: 40000.000000 <= 40000.000000
0 <= CUSTOMER_2|PRODUCT_TYPE_1: 10000.000000 <= 25000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_1: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_2: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_3: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_4: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_5: 0 <= 15000.000000
0 <= CUSTOMER_4|PRODUCT_TYPE_1: 0 <= 5000.000000
0 <= CUSTOMER_4|PRODUCT_TYPE_2: 0 <= 5000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_2: 0 <= 2000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_3: 0 <= 2000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_4: 0 <= 2000.000000
0 <= CUSTOMER_6|PRODUCT_TYPE_2: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_3: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_4: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_5: 0

And Sometime this :

---- Error formula ------
OPTIMAL 49998.917986454384 @ [23731.0, 25000.0, 1269.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0185623563218, 0.425287356322, -0.490112643678, -0.574712643678, -0.574712643678]

0 <= CUSTOMER_1|PRODUCT_TYPE_1: 23731.000000 <= 40000.000000
0 <= CUSTOMER_2|PRODUCT_TYPE_1: 25000.000000 <= 25000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_1: 1269.000000 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_2: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_3: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_4: 0 <= 15000.000000
0 <= CUSTOMER_3|PRODUCT_TYPE_5: 0 <= 15000.000000
0 <= CUSTOMER_4|PRODUCT_TYPE_1: 0 <= 5000.000000
0 <= CUSTOMER_4|PRODUCT_TYPE_2: 0 <= 5000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_2: 0 <= 2000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_3: 0 <= 2000.000000
0 <= CUSTOMER_5|PRODUCT_TYPE_4: 0 <= 2000.000000
0 <= CUSTOMER_6|PRODUCT_TYPE_2: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_3: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_4: 0
0 <= CUSTOMER_6|PRODUCT_TYPE_5: 0

MarkowitzModel is hanging on low target risk

Hello,

I'm using ojAlgo for the MVO purposes. It works good with 33 expected returns.
But when I'm passing 35 expected returns in the constructor(and 35 * 35 covariance table) - program is hanging on any get method of MarkowitzModel.

Please let me know if you need more information.

Thanks in advance!

InverterTask.invert goes into Infinite loop in case of some specific large matrices

This is the test code for reproducing the issue.

  @Test
  public void test_invert_large_matrix() throws TaskException {
    double[][] data = new double[3000][3000];
    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data.length; j++) {
        data[i][j] = 0.9;
      }
    }
    data[0][1] = 1.01;

    PrimitiveMatrix input = PrimitiveMatrix.FACTORY.rows(data);
    double[][] inv = SingularValue.make(input).invert(input.toPrimitiveStore()).toRawCopy2D();

    // The issue:can't  be reached here!!!
  }

The reason may be that, after the following line(No.144) of the current SVDnew32 class ,the value the shift local variable becomes NaN in this case.

shift = c / (b + shift);

Test code errors in eclipse

I added ojAlgo built jars(version 40.0) to eclipse and made a project for the test code. I got three compiled errors.
screenshot 10
screenshot 11
screenshot 12

Allow access to eigenvalues of RawEigenvalue without creating an additional Array1D instance

RawEigenvalue.getEigenvalues() returns the eigenvalues as an Array1D<ComplexNumber>. It creates a new Array1D and fills the array with the real and complex components of the eigenvalues. The components are accessed via RawEigenvalue.getRealEigenvalues() and RawEigenvalue.getImagEigenvalues() that both just return references to member variables:
https://github.com/optimatika/ojAlgo/blob/master/src/org/ojalgo/matrix/decomposition/RawEigenvalue.java#L234-L248
I would like to access the eigenvalues without creating any objects. However, getRealEigenvalues and getImagEigenvalues are private and I am forced to use getEigenvalues instead. This could be resolved easily by making these methods public.

edit: I just realized that it will not be as straight forward as I had imagined given that RawEigenvalue is package private.

String too long

Hi,

in the two test files:
org.ojalgo.opsimisation.convex.ConvexProblems.java (Line 935)
org.ojalgo.opsimisation.convex.QuadraticProblems.java (Line 141)

there's a Stringbuilder qs, which holds around 65k elements.
Java is complaining that this is too much (even Netbeans warns me because it could crash).

Maybe it's possible to split these up in multiple definitions and concat them later?

Greetings

primitve float type

I recently learnt about ojalgo, and I did a few quick tests / poking around the code (for convex optimizations). It looks really really (really) impressive. One question though: since we're doing lots of high performance computing (10s of millions of tiny convex optimizations (eg matrix size is ~20)), my initial thoughts that if the ojaglo provides a "primitive float" matrix representation (instead of double), we could relatively easily achieve up to 2x performance gain (or am I missing something?) (I calculated the "up to 2x" because I believe floats use 1/2 CPU cycles (and memory) as doubles; and even if some portion of the CPU time is spent doing something else other than actual computations (eg dealing with loop counters and memory pointers etc), the fact that the memory space required is halves may have significant benefits when it comes to L1/L2/L3 caching etc. (I'm also assuming that there may be some semi-automated way to generate all the needed classes but just substitute "double" for "float" everywhere.) Thoughts?

OPTIMAL but should be INFEASIBLE

Run the following code:

Variable x = Variable.make("x").lower(0).weight(2);
Variable y = Variable.make("y").lower(0).weight(-1);
Variable z = Variable.make("z").lower(0).weight(4);

ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);
model.addVariable(z);

model.addExpression().set(x, 3).set(y, 2).set(z, 2).upper(0);
model.addExpression().set(x, 0).set(y, 3).set(z, -2).lower(2);

Optimisation.Result solution = model.maximise();
System.out.println(solution);

model.options.debug(LinearSolver.class);
System.out.println(model.validate(solution));

The output is

OPTIMAL -0.666666666667 @ [0.0, 0.666666666667, 0.0]
1.333333333334 ! EXPR0 <= 0
false

so the found "optimal" solution violates the constraints. I don't think there's a any solution, because from 3x + 2y + 2z <= 0, x,y,z >=0 follows x = y = z = 0, and then the second constraint is impossible to respect.

Maybe it would be possible to write some tests that try to solve random problems and if the solution is OPTIMAL check if it's actually in the feasible region?

ojAlgo cannot solve large linear programs since version 41.0.0

Hi,

I found that since version 41.0.0, ojAlgo cannot solve large linear programs (everything works fine in version 40.0.0).

You can do as follows to reproduce the issue:

Clone my repository
git clone -b reproduce_ojalgo_issue https://github.com/hoangtungdinh/BeSwarm.git
Run the following gradle task
gradle reproduceOjAlgoIssue

The gradle task will execute the following class: io.github.hoangtungdinh.beswarm.solvers.profiler.OjSolverIssue, which creates and solves 3 different linear programs (one small program, two big programs), using ojAlgo v40. All 3 linear programs are solved.

You then can change the version of ojAlgo in build.gradle to v41 and v42 and execute the gradle task again. Only the first linear program (the small one) is solved. OjAlgo cannot solve the last two linear programs.

As it is quite hard to see the linear program model in my code, I generated a .mps file for each model (using the export functionality from CPLEX). You can find them in my repository (problem1, problem2, problem3)

Unfortunately, ojAlgo cannot read those files. My attempt to read those files can be found here. The MathProgSysModel throws a NumberFormatException.

Stack Overflow at ExpressionBasedModel#presolve(ExpressionsBasedModel)

Hi,

First of all, thanks for open sourcing this promising library. I am evaluating it against JOptimise and I found that the current implementation of the presolve function in ExpressionsBasedModel causes a stack overflow because of the recursive call on line 125 (version 38).

I suggest doing 3 things:

  1. use this code instead:
    /**
     * Avoids stack overflow exceptions caused by the original  {@link ExpressionsBasedModel#presolve()}.
     *
     * @param model
     */
    public static final void presolveIterative(final ExpressionsBasedModel model) {

        int iters = 0;
        boolean stillSimplifying = true;
        while (stillSimplifying) {
            ++iters;
            if (iters % 100 == 0) {
                log.info("Done {} iterations of presolving");
            }

            stillSimplifying = false;

            for (final Expression tmpExpression : model.getExpressions()) {
                if (tmpExpression.simplify()) {
                    log.debug("Following expression is now redundant: {}", tmpExpression);
                    stillSimplifying = true;
                    break; // Restart the process after removing something.
                }
            }
        }
    }
  1. Make the presolve functions normal methods.. you have one presolve function as final and the other as static, which prevents subclasses from overriding either. This makes it unnecessarily harder to extend your library, and yet not impossible.

  2. Create a tag on github for each release, so that anybody can fork the version they are using and submit a bug fix pull request. Right now I would need to pull master and fix the bug in a version that is unstable and not ready for release.

Thanks again.

Releases not in Maven central

The only version in maven central repository is the 31.0.
It would be great to have past releases in the central repository, as it would make it much easier to depend on your project.
For instance the "tweety" project depends on ojalgo 35, making it very difficult to use.

It would be great to have all releases in a maven repository (central or custom).

INFEASIBLE for linear program, should be DISTINCT

Run the following code:

Variable x = Variable.make("x").lower(0);
Variable y = Variable.make("y").lower(0);

ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);

model.addExpression("first").set(x, 2).set(y, 3).upper(1);
model.addExpression("second").set(x, -2).set(y, 3).lower(1);

Optimisation.Result result = model.maximise();
System.out.println(result);

The output is

INFEASIBLE 0.0 @ [0.0, 0.3333333333333333]

But the problem is actually feasible, the solution [0, 1/3] respects both constraints. The output should be

DISTINCT 0.0 @ [0.0, 0.3333333333333333]

I'm not sure what went wrong, maybe the precision isn't good enough? Is there a way to get the solver to run on rational numbers instead of BigDecimal?

Surprisingly slow on fairly small problem

On a 5520-binary-variable (all weighted) 500-expression ExpressionsBasedModel minimise, ojalgo can take up to 8GB of ram and 8 seconds. (In our case, the time is acceptable, but the RAM usage is too high.) The model happens to be calculating a subgraph (each binary variable representing an edge).

If I directly build a LinearSolver as follows (which I guess is solving the linear relaxation?),

model.setMinimisation();
Builder b = LinearSolver.getBuilder();
LinearSolver.copy(model, b);
Result linearResult = b.build().solve();

then it performs somewhat better (6 seconds), but unfortunately I need to use reflection to invoke model.handleResult(linearResult) because it is private, so I can't really use this trick in production. Either way, the memory usage seems to be happening here.

GLPK solves this same problem in a couple MB of RAM and 100ms, so it seems like it must be doing something fundamentally different, but I'm not sure what.

Is this the expected performance, and are there any tricks that can be used to speed things up?

Use of logging lib instead of BasicLogger

Hello, @apete,
Do you have any plans to switch to some known logging library? For example slf4j? If yes - probably I could contribute switching to it keeping BasicLogger deprecated for API compatibility.

A question about Sparse

I am working to find a decent Java or Scala Matrix library to support large amounts of data for streamed learning. I have tried Breeze but ran into a memory issue at a relatively small 1000 * 50000 size matrix, a size Scipy handles with ease. Since I do a lot of mixed operations (in and out of the library), I was wondering, are you planning on creating an optimized Sparse library at any point?

What is the correct way to add rows/columns to a SparseStore?

My use case for this library involves building up an in-memory store of information from streaming data and thus adding rows or columns to a matrix as new data comes in. It seemed from examining the source that Store objects have a fixed size and the only way to grow them would be to copy them into a new object, like so:

SparseStore<Double> sparseStore = SparseStore.makePrimitive(NUM_ROWS, NUM_COLS);
SparseStore<Double> sparseStore2 = SparseStore.makePrimitive((int) sparseStore.countRows(), (int) sparseStore.countColumns() + 1);
sparseStore2.accept(sparseStore);
sparseStore2.add(sparseStore.countRows() - 1, sparseStore.countColumns(), 42);

However, for NUM_ROWS = NUM_COLS = 100000, the time it took to execute this code was ~15s, and seemed to grow exponentially as I increased matrix size. Is there a more efficient way to simply add a row/column to a matrix?

Implement non-linear constraints

The original SO question: https://stackoverflow.com/q/47378153/3144601

Currently it is possible to create a model with non-linear constraints, but solving it results in an NPE.

Please:

  • Provide a clear error instead of an NPE
  • Implement an assertion in the method that sets a quadratic constraint like set(Variable, Variable, value)
  • Describe all currently unsupported features in the documentation
  • Implement quadratic constraints in the solver

Tests randomly fail

I can't build the library right now, RandomNumberTest or SingularValueTest sometimes fail, with a different error each time.

Example 1
Failed tests:   testGamma(org.ojalgo.random.RandomNumberTest): Sample mean was 1.028919709412292, distribution mean was 1.0. expected:<1.028919709412292> but was:<1.0>

Tests run: 209, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42.268 s
[INFO] Finished at: 2018-03-12T08:56:40+01:00
[INFO] Final Memory: 28M/603M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ojalgo: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ojalgo: There are test failures.

Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution (SurefireHelper.java:83)
    at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary (SurefirePlugin.java:176)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:150)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:650)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:586)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Example 2
Failed tests:   testSampledMean(org.ojalgo.random.RandomNumberTest): Normal expected:<0.0> but was:<-0.11502726781557226>

Tests run: 209, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.163 s
[INFO] Finished at: 2018-03-12T09:02:31+01:00
[INFO] Final Memory: 27M/512M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ojalgo: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project ojalgo: There are test failures.

Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to C:\Users\Karel\Desktop\Build ojalgo\ojAlgo\target\surefire-reports for the individual test results.
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution (SurefireHelper.java:83)
    at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary (SurefirePlugin.java:176)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:150)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:650)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:586)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Example 3
Tests run: 12, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.437 sec <<< FAILURE!
testRandomSquareCase(org.ojalgo.matrix.decomposition.SingularValueTest)  Time elapsed: 0.172 sec  <<< FAILURE!
junit.framework.AssertionFailedError: SingularValue<N> expected:<org.ojalgo.matrix.store.ComplexDenseStore < 8 x 8 >
{ { (2.499760451917726 + 0.0i), (3.527743685995949 + 0.0i),     (4.662817999466646 + 0.0i),     (1.72385992683264 + 0.0i),      (0.5016446420697318 + 0.0i),    (0.6492300247497718 + 0.0i),    (0.8649010160270714 + 0.0i),    (5.284843046949209 + 0.0i) },
{ (4.720300689611867 + 0.0i),   (5.818099693236926 + 0.0i),     (5.233818146710731 + 0.0i),     (5.855018809932886 + 0.0i),     (3.115252481075881 + 0.0i),     (0.4322693249379133 + 0.0i),    (2.427494584928736 + 0.0i),     (4.372492677517891 + 0.0i) },
{ (0.5429143524013447 + 0.0i),  (5.854762978372245 + 0.0i),     (0.5871183803917388 + 0.0i),    (1.543608260272446 + 0.0i),     (5.615910892380532 + 0.0i),     (2.592839254088847 + 0.0i),     (5.856072690786387 + 0.0i),     (3.912850406439847 + 0.0i) },
{ (3.785903695647925 + 0.0i),   (3.102257911284102 + 0.0i),     (4.5991272580882 + 0.0i),       (3.169646493223153 + 0.0i),     (2.737985087892073 + 0.0i),     (5.829978083465515 + 0.0i),     (2.876076869243659 + 0.0i),     (0.6238520547358823 + 0.0i) },
{ (0.4235461382009782 + 0.0i),  (4.844381059710229 + 0.0i),     (4.424326818716773 + 0.0i),     (1.683217622674778 + 0.0i),     (2.693340688760603 + 0.0i),     (4.325228958715321 + 0.0i),     (0.4303888604902877 + 0.0i),    (1.117834472065064 + 0.0i) },
{ (1.246664026040171 + 0.0i),   (4.241241136192584 + 0.0i),     (2.81535004790768 + 0.0i),      (1.127494617111985 + 0.0i),     (5.686731885514387 + 0.0i),     (2.029373262439739 + 0.0i),     (0.5788577104332049 + 0.0i),    (1.302404970210216 + 0.0i) },
{ (2.770725618528353 + 0.0i),   (3.960398059304565 + 0.0i),     (0.4243580427698515 + 0.0i),    (0.9258721746506664 + 0.0i),    (2.570699488516595 + 0.0i),     (0.4365187611937791 + 0.0i),    (0.9853339018619005 + 0.0i),    (5.287773532294669 + 0.0i) },
{ (5.701957359834497 + 0.0i),   (4.053991345544266 + 0.0i),     (5.609892913977285 + 0.0i),     (5.848511729499727 + 0.0i),     (3.519923282955612 + 0.0i),     (0.4363689725862376 + 0.0i),    (2.117924047270422 + 0.0i),     (2.944719800520183 + 0.0i) } }> but was:<org.ojalgo.matrix.decomposition.SingularValueDecomposition$Complex@4563e9ab>
        at junit.framework.Assert.fail(Assert.java:57)
        at junit.framework.Assert.failNotEquals(Assert.java:329)
        at org.ojalgo.TestUtils.assertEquals(TestUtils.java:181)
        at org.ojalgo.matrix.decomposition.SingularValueTest.doTestTypes(SingularValueTest.java:337)
        at org.ojalgo.matrix.decomposition.SingularValueTest.testRandomSquareCase(SingularValueTest.java:205)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at junit.framework.TestCase.runTest(TestCase.java:176)
        at junit.framework.TestCase.runBare(TestCase.java:141)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:129)
        at junit.framework.TestSuite.runTest(TestSuite.java:252)
        at junit.framework.TestSuite.run(TestSuite.java:247)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

And then RandomNumberTest got stuck and I had to terminate the tests.

Submatrix as a view

Does ojAlgo support a submatrix as views? That is a submatrix does not make copy of data but instead pointing to data in the original matrix.

A potential calculation issue of MarkowitzModel

hi there,

Below test case is failed, could you please have a check?
Attached is an reference document to design the test case. FYI.

Regards,
Edward

portfolioTheoryMatrix.pdf

BasicMatrix.Factory matrixFactory = PrimitiveMatrix.FACTORY;
PrimitiveMatrix cov = matrixFactory.rows(new double[][] { { 0.01, 0.0018, 0.0011 }, { 0.0018, 0.0109, 0.0026 },
{ 0.0011, 0.0026, 0.0199 } });
PrimitiveMatrix ret = matrixFactory.columns(new double[] { 0.0427, 0.0015, 0.0285 });
BigDecimal riskAversion = new BigDecimal(1000000);
MarketEquilibrium marketEquilibrium = new MarketEquilibrium(cov, riskAversion);
MarkowitzModel markowitz = new MarkowitzModel(marketEquilibrium, ret);
markowitz.setShortingAllowed(true);
markowitz.setTargetReturn(BigDecimal.valueOf(0.0427));
assert (FloatUtil.equal(markowitz.getWeights().get(0).doubleValue(), 0.82745, FloatUtil.Precision.P5));
assert (FloatUtil.equal(markowitz.getWeights().get(1).doubleValue(), -0.09075, FloatUtil.Precision.P5));
assert (FloatUtil.equal(markowitz.getWeights().get(2).doubleValue(), 0.26329, FloatUtil.Precision.P5));
assert (FloatUtil.equal(markowitz.getMeanReturn(), 0.0427, FloatUtil.Precision.P4));
assert (FloatUtil.equal(markowitz.getReturnVariance(), 0.0084, FloatUtil.Precision.P4));

Schur

Tag bort eller gör om.

maven build failed for the code checked in apete 2016-01-12.

[INFO] Compiling 436 source files to C:\Programs\ojAlgo-master\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.185 s
[INFO] Finished at: 2016-01-18T00:59:38-05:00
[INFO] Final Memory: 16M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project ojalgo: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Bug in ConvexSolver with inequality constraints but no equality constraints

Hi,

I recently upgraded to v38.2 of Ojalgo for solving some quadratic programs. It seems that somewhere in the code there is an assumption that whenever there are inequality constraints there must be at least one equality constraint. My problem has a bunch of inequality constraints but no equality constraints and running it gives a "divide by zero" error. Again, this only seems to manifest itself when there are inequality constraints but no equality constraints.

I have reproduced it below with a simple example.

scala> val P = Array(Array(1.0, 0), Array(0, 1.0))
val c = Array(0.0, 0.0)
val Q = PrimitiveDenseStore.FACTORY.rows(P:_*).builder().build()
val C = PrimitiveDenseStore.FACTORY.columns(c).builder().build()
val myBuilderI = new ConvexSolver.Builder(Q, C)

val ai = Array(Array(1.0, 1.0))
val rhs = Array(1.0)

myBuilderI.inequalities(PrimitiveDenseStore.FACTORY.rows(ai:_*).builder().build(), PrimitiveDenseStore.FACTORY.columns(rhs).builder().build())

val prob = myBuilderI.build()
val solved = prob.solve()

scala> java.lang.ArithmeticException: / by zero
at org.ojalgo.matrix.store.PrimitiveDenseStore.fillByMultiplying(PrimitiveDenseStore.java:1199)
at org.ojalgo.matrix.store.MatrixStore.multiply(MatrixStore.java:438)
at org.ojalgo.matrix.store.MatrixStore.multiply(MatrixStore.java:432)
at org.ojalgo.optimisation.convex.ActiveSetSolver.performIteration(ActiveSetSolver.java:412)
at org.ojalgo.optimisation.convex.ConvexSolver.solve(ConvexSolver.java:310)
at org.ojalgo.optimisation.Optimisation$Solver.solve(Optimisation.java:383)

Off-by-one error in MultiplyRight.invoke for SparseStore

In v44.0.0, lines 717-722 of MultiplyRight say this:

        final int tmpFirstInColumn = MatrixUtils.firstInColumn(right, j, 0);
        final int tmpLimitOfColumn = MatrixUtils.limitOfColumn(right, j, complexity);

        for (int c = tmpFirstInColumn; c < tmpLimitOfColumn; c++) {
            AXPY.invoke(product, j * tmpRowDim, 1, right.doubleValue(c + (j * complexity)), left, c * tmpRowDim, 1, 0, tmpRowDim);
        }

I believe there's a bug either in MatrixUtils.limitOfColumn or in its usage here, which can cause the last element in a column to be ignored. For example, the following Scala code incorrectly computes [1 0; 0 0; 0 0] * [1 0; 0 1] = [0 0; 0 0; 0 0] with SparseStores:

val m = SparseStore.PRIMITIVE.make(3, 2)
val n = m.add(PrimitiveDenseStore.FACTORY.rows(Array(1.0, 0.0), Array(0.0, 0.0), Array(0.0, 0.0)))
val eye = SparseStore.PRIMITIVE.make(2, 2)
eye.set(0, 0, 1.0)
eye.set(1, 1, 1.0)
val prod = n.multiply(eye)
println(n.toRawCopy2D.map(_.toSeq).toSeq) // WrappedArray(WrappedArray(1.0, 0.0), WrappedArray(0.0, 0.0), WrappedArray(0.0, 0.0))
println(eye.toRawCopy2D.map(_.toSeq).toSeq) // WrappedArray(WrappedArray(1.0, 0.0), WrappedArray(0.0, 1.0))
println(prod.toRawCopy2D.map(_.toSeq).toSeq) // WrappedArray(WrappedArray(0.0, 0.0), WrappedArray(0.0, 0.0), WrappedArray(0.0, 0.0))

I'm not sure whether MatrixUtils.limitOfColumn is meant to return the index of the last nonzero in the column (in which case the limit in the for-loop is wrong), or one greater than that. I believe it's the latter, because for nonsparse matrices it would return 2 in this case.

UNBOUNDED but should be INFEASIBLE

Run the following code:

Variable x = Variable.make("x").lower(0).weight(1);
Variable y = Variable.make("y").lower(0).weight(0);

ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);

model.addExpression("first").set(x, 0).set(y, 1).lower(1);
model.addExpression("second").set(x, 0).set(y, 1).upper(-1);

ExpressionsBasedModel.clearPresolvers();

Optimisation.Result result = model.maximise();
System.out.println(result);

This prints UNBOUNDED 0.0 @ [0.0, 0.0], but the problem is actually infeasible, since y can't be >=1 and <=-1.

This is kind of a dumb edge case so feel free to close it as such, I'm reporting it just in case.

Optimization - Don't require names for variables and expressions

Hi there,

I've been having a great time with ojAlgo optimization and have even started a series of blog articles on it. I also have a clear plan for some okAlgo extensions which I will donate later to optimatika if they are wanted.

One thing I find myself doing frequently is creating Kotlin extensions on ExpressionsBasedModel to not require names for variables or expressions. It's a bit of a pain to concatenate name arguments especially when my OOP design will organize the variables for me. For instance:

data class Driver(val driverNumber: Int,
                  val rate: Double,
                  val availability: IntRange? = null) {

    val shiftStart = variable().lower(6).upper(22)
    val shiftEnd = variable().lower(6).upper(22)
}

I don't care about naming the variables, and I typically will just assign an incremented numeric name to a variable automatically using Kotlin extensions like this:

// custom DSL for  expression and variable inputs, eliminate naming and adding
val funcId = AtomicInteger(0)
val variableId = AtomicInteger(0)
fun variable() = Variable(variableId.incrementAndGet().toString().let { "Variable$it" })
fun ExpressionsBasedModel.addExpression() = funcId.incrementAndGet().let { "Func$it"}

Before I start building closure API's for okAlgo, I wanted to propose adding some overloads to eliminate the requirement to name variables and expressions.

Proposal for "okAlgo" project

Hey there,

I've been playing with this library a lot and I love it. I have been using it heavily with Kotlin, and I have already been saving some extension functions and DSL's I have found useful.

Would it be okay if I start an "okAlgo" project that provides Kotlin idiomatic extensions to ojAlgo? We can put it under the "optimatika" domain or my own, whichever you like better...

I did something similar with Apache Commons Math with Kotlin-Statistics, which has been successful.

https://github.com/thomasnield/kotlin-statistics

Performance issue solving LIP

Hi,

I have a performance issue solving a binary integer problem.

Situation:
N = 200

Cond1_lower <= x_1*w_11 + ........ + x_N*w_1N <= Cond1_upper

Cond2_lower <= x_1*w_21 + ........ + x_N*w_2N <= Cond2_upper

Cond3_lower <= x_1*w_31 + ........ + x_N*w_3N <= Cond3_upper

and maiximize: z = x_1*v1 + ....... + x_N*v_N.

We would like to use java to solve this issue but it takes too long to solve it (never really got a result). We have a C library to solve this problem and it takes about 500ms.

I hope you can help me figure out what we are doing something.

public class Sample {

	private static final Random RANDOM = new Random();

	// Weighting so we don't have preference to smaller or bigger container
	private static final int MAX_OBJECTIVE_VALUE = 1000000000;

	private static final double DEVIATION = 0.02D;

	private static final double FIRST_CONTAINER_SIZE_PERC = 0.8;
	private static final double SECOND_CONTAINER_SIZE_PERC = 0.1;
	private static final double THIRD_CONTAINER_SIZE_PERC = 0.1;

	public static void main(String[] args) {
		List<Container> containers = Arrays.asList(
				new Container("first", 75280),
				new Container("second", 57600),
				new Container("third", 75280),
				new Container("first", 104000),
				new Container("first", 156000),
				new Container("first", 140040),
				new Container("third", 68000),
				new Container("first", 106560),
				new Container("first", 158560),
				new Container("third", 70240),
				new Container("first", 62080),
				new Container("first", 70240),
				new Container("first", 105000),
				new Container("second", 115440),
				new Container("first", 68000),
				new Container("first", 134880),
				new Container("first", 171360),
				new Container("first", 122400),
				new Container("second", 57600),
				new Container("first", 162600),
				new Container("first", 112800),
				new Container("first", 130080),
				new Container("first", 102000),
				new Container("first", 104160),
				new Container("first", 105840),
				new Container("first", 89800),
				new Container("first", 104160),
				new Container("first", 107200),
				new Container("first", 175520),
				new Container("first", 119040),
				new Container("first", 75360),
				new Container("third", 84000),
				new Container("first", 60000),
				new Container("second", 184960),
				new Container("first", 113600),
				new Container("first", 84000),
				new Container("first", 196800),
				new Container("third", 74080),
				new Container("first", 110520),
				new Container("first", 86000),
				new Container("first", 125280),
				new Container("first", 158880),
				new Container("first", 108960),
				new Container("third", 72432),
				new Container("second", 26400),
				new Container("first", 149040),
				new Container("first", 129920),
				new Container("third", 72800),
				new Container("first", 74080),
				new Container("second", 100800),
				new Container("first", 107200),
				new Container("first", 70080),
				new Container("first", 75040),
				new Container("first", 148320),
				new Container("first", 66240),
				new Container("first", 89840),
				new Container("first", 167200),
				new Container("first", 122000),
				new Container("first", 233280),
				new Container("second", 63000),
				new Container("first", 81600),
				new Container("first", 74080),
				new Container("first", 71520),
				new Container("first", 205760),
				new Container("first", 132960),
				new Container("first", 71520),
				new Container("first", 136200),
				new Container("first", 145440),
				new Container("first", 164200),
				new Container("third", 65920),
				new Container("first", 77600),
				new Container("first", 73280),
				new Container("first", 112800),
				new Container("first", 132480),
				new Container("first", 126240),
				new Container("first", 166560),
				new Container("first", 100640),
				new Container("first", 70080),
				new Container("first", 116800),
				new Container("first", 121600),
				new Container("first", 95360),
				new Container("first", 113760),
				new Container("first", 184800),
				new Container("first", 105840),
				new Container("third", 86560),
				new Container("first", 146400),
				new Container("first", 72800),
				new Container("first", 98400),
				new Container("second", 62400),
				new Container("first", 101600),
				new Container("first", 72432),
				new Container("third", 75360),
				new Container("second", 208800),
				new Container("second", 120600),
				new Container("first", 154880),
				new Container("second", 184800),
				new Container("first", 64800),
				new Container("first", 102500),
				new Container("first", 121600),
				new Container("first", 68640),
				new Container("first", 200640),
				new Container("first", 129120),
				new Container("second", 37200),
				new Container("first", 132960),
				new Container("first", 95200),
				new Container("first", 105120),
				new Container("second", 26400),
				new Container("first", 268880),
				new Container("first", 126720),
				new Container("first", 120320),
				new Container("first", 108000),
				new Container("first", 115680),
				new Container("second", 238800),
				new Container("first", 98400),
				new Container("third", 72320),
				new Container("first", 72320),
				new Container("first", 96480),
				new Container("first", 72800),
				new Container("first", 67200),
				new Container("second", 75040),
				new Container("first", 113760),
				new Container("third", 76160),
				new Container("first", 70400),
				new Container("first", 133920),
				new Container("first", 107040),
				new Container("first", 136800),
				new Container("first", 76160),
				new Container("second", 115500),
				new Container("first", 100800),
				new Container("first", 72240),
				new Container("first", 72640),
				new Container("first", 82640),
				new Container("first", 97600),
				new Container("third", 82640),
				new Container("first", 129120),
				new Container("first", 124800),
				new Container("first", 112800),
				new Container("first", 76000),
				new Container("second", 43200),
				new Container("first", 83200),
				new Container("first", 101600),
				new Container("second", 25500),
				new Container("second", 31200),
				new Container("first", 219200),
				new Container("first", 97440),
				new Container("first", 144960),
				new Container("first", 105120),
				new Container("third", 97680),
				new Container("first", 114400),
				new Container("first", 93120),
				new Container("first", 162720),
				new Container("second", 36000),
				new Container("first", 105840),
				new Container("first", 68800),
				new Container("first", 108000),
				new Container("first", 130560),
				new Container("third", 74080),
				new Container("first", 126400),
				new Container("first", 120960),
				new Container("first", 75040),
				new Container("third", 68800),
				new Container("second", 107200),
				new Container("first", 130560),
				new Container("first", 106800),
				new Container("first", 153120),
				new Container("third", 75040),
				new Container("second", 117240),
				new Container("third", 166800),
				new Container("first", 130880),
				new Container("first", 86560),
				new Container("second", 72640),
				new Container("first", 94080),
				new Container("first", 132000),
				new Container("first", 132960),
				new Container("first", 73200),
				new Container("first", 122880),
				new Container("first", 103200),
				new Container("first", 162720),
				new Container("first", 73920),
				new Container("first", 120000),
				new Container("second", 126400),
				new Container("third", 76000),
				new Container("first", 160800),
				new Container("third", 66240),
				new Container("second", 48000),
				new Container("second", 70800),
				new Container("first", 73920),
				new Container("first", 122080),
				new Container("first", 125280),
				new Container("first", 88480),
				new Container("first", 141600),
				new Container("first", 129000),
				new Container("first", 65920),
				new Container("first", 137000),
				new Container("first", 173280),
				new Container("first", 124640),
				new Container("second", 33540));

		new Sample().solve(2700000L, containers);
	}

	private void solve(long maxContainerSize, List<Container> containers) {
		Optimisation.Options options = new Optimisation.Options();
		options.iterations_suffice = 64;

		ExpressionsBasedModel expressionsBasedModel = new ExpressionsBasedModel(options);

		double firstContainerSize = maxContainerSize * FIRST_CONTAINER_SIZE_PERC;
		Expression firstContainerExpression = expressionsBasedModel
				.addExpression("expression:first")
				.lower(firstContainerSize * (1 - DEVIATION)).upper(firstContainerSize * (1 + DEVIATION));


		double secondContainerSize = maxContainerSize * SECOND_CONTAINER_SIZE_PERC;
		Expression secondContainerExpression = expressionsBasedModel
				.addExpression("expression:second")
				.lower(secondContainerSize * (1 - DEVIATION)).upper(secondContainerSize * (1 + DEVIATION));

		double thridContainerSize = maxContainerSize * THIRD_CONTAINER_SIZE_PERC;
		Expression thirdContainerExpression = expressionsBasedModel
				.addExpression("expression:third")
				.lower(thridContainerSize * (1 - DEVIATION)).upper(thridContainerSize * (1 + DEVIATION));

		for (int cIndex = 0; cIndex < containers.size(); cIndex++) {
			Container container = containers.get(cIndex);
			Variable variable = Variable.make("v" + cIndex)
					.weight(RANDOM.nextInt(MAX_OBJECTIVE_VALUE) * container.getSize())
					.binary();

			expressionsBasedModel.addVariable(variable);

			if (container.getType().equals("first")) {
				firstContainerExpression.set(variable, container.getSize());
			}

			if (container.getType().equals("second")) {
				secondContainerExpression.set(variable, container.getSize());
			}

			if (container.getType().equals("third")) {
				thirdContainerExpression.set(variable, container.getSize());
			}
		}

		Optimisation.Result result = expressionsBasedModel.maximise();

		List<Container> resultContainer = new ArrayList<>();
		for (int cIndex = 0; cIndex < containers.size(); cIndex++) {
			BigDecimal bigDecimal = result.get(cIndex);
			if (bigDecimal.compareTo(BigDecimal.ZERO) > 0) {
				resultContainer.add(containers.get(cIndex));
			}
		}

		System.out.println("RESULT: " + resultContainer.size());
	}

	static class Container {

		private String type;
		private double size;

		public Container(String type, long size) {
			this.type = type;
			this.size = size;
		}

		public String getType() {
			return type;
		}

		public double getSize() {
			return size;
		}
	}

}

Primitive double to RationalNumber

There are 5 methods in RationalNumber that take primitive double as input:

RationalNumber#valueOf(double)
RationalNumber#add(double)
RationalNumber#subtract(double)
RationalNumber#multiply(double)
RationalNumber#divide(double)

Their implementations all create various Objects before arriving at the long numerator and denominator of the "new" RationalNumber instance. It should be possible to go directly from the input double to corresponding long numerator and denominator without creating any intermediate Object.

double arg => long numerator, denominator

NumberFormatException raised processing MPS file

Creation of a model from MPS file fails. I first tried with a CPLEX-created MPS file and I got a NumberFormatException. Then I tried with a simple MPS instance and it worked. When I modified coefficients to include decimal digits, I got the exception again. Here is the exception I got calling MathProgSysModel.make(fileName):

Exception in thread "main" java.lang.NumberFormatException
at java.math.BigDecimal.(BigDecimal.java:596)
at java.math.BigDecimal.(BigDecimal.java:383)
at java.math.BigDecimal.(BigDecimal.java:806)
at org.ojalgo.optimisation.MathProgSysModel.parseSectionLine(MathProgSysModel.java:633)
at org.ojalgo.optimisation.MathProgSysModel.make(MathProgSysModel.java:400)

Here is the MPS test file I used. It works fine with CPLEX. The exception is raised when parseSectionLine processes the first line of the COLUMNS section. If you remove all decimals and leave integer numbers, the code works fine.

NAME          TESTPROB
ROWS
 N  COST
 L  LIM1
 G  LIM2
 E  MYEQN
COLUMNS
    XONE      COST                 1.1   LIM1                 1.1
    XONE      LIM2                 1.1
    YTWO      COST                 4.1   LIM1                 1.1
    YTWO      MYEQN               -1.1
    ZTHREE    COST                 9.1   LIM2                 1.1
    ZTHREE    MYEQN                1.1
RHS
    RHS1      LIM1                 5.1   LIM2                10.1
    RHS1      MYEQN                7.1
BOUNDS
 UP BND1      XONE                 4.1
 LO BND1      YTWO                -1.1
 UP BND1      YTWO                 1.1
ENDATA

Test/correct quaternion functions

The quaternion trigonometric and hyperbolic functions, defined in org.ojalgo.function.QuaternionFunction, needs to be reviewed and most likely fixed.

INFEASIBLE but should be DISTINCT

Run the following code:

Variable x = Variable.make("x").lower(0).weight(3);
Variable y = Variable.make("y").lower(0).weight(-2);

ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);

model.addExpression().set(x, -1).set(y, 0).lower(0);
model.addExpression().set(x, -1).set(y, 3).level(2);

Optimisation.Result solution = model.maximise();
System.out.println(solution);

The result is INFEASIBLE -1.3333333333333333 @ [0.0, 0.6666666666666666], but the program is actually DISTINCT: the point (0, 1/3 2/3) doesn't conflict with any of the constraints:

x >= 0
y >= 0
-x >= 0
-x + 3y = 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.