Hi.

Le mar. 10 août 2021 à 17:38, Jorge Garcia de Alba
<[email protected]> a écrit :
>
> Hello,
>
> Would apache commons math be interested in adding code that could
> easily be used in java language routines or is this out of scope? I
> think they would be the best choice for implementing this.
>
> This is how I imagine it would be used.
> https://github.com/xjrga/linearprogramming

Is the "LPModel" class[1] which I should look at?

This code is extremely fragile: All the callers within a single JVM
are mutating the same data (a global variable indeed).

If you require C-like behaviour (through Java "static" functions),
you should at least have the caller create his own "LPModel"
instance and have the function(s) take that as an argument.
For example:

public class LPModel {
    private final ArrayList<LinearConstraint> constraints;
    // etc..
    // -> Remove "static" from _all_ fields (no global data).

    // Define a constructor.
    public LPModel(/* arguments */) {
        constraints = ... // Initialize from the constructor's arguments.
    }

    public static class Solution {
        // -> A container for the result of a computation.
    }

    public Solution solve() {
       // ...
    }
}

Then if there is a high-level requirement for calling through static
functions, you'd create a "utility" class:

public class LPModelUtils {
    // Instance creation function.
    public static LPModel create(/* arguments */) {
        return new LPModel(/* arguments */);
    }

    // Solver function.
    public LPModel.solution solve(LPModel instance) {
        return instance.solve();
    }
}

> Here is information on java language routines.
> http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_jrt_routines

Thanks.  This is high-level requirement that would probably
call into an intermediate level doing the adaptation to the
low-level Commons Math (CM) API; I don't think that it can
provide useful hints about what the CM API should look like.

Best regards,
Gilles

[1] 
https://github.com/xjrga/linearprogramming/blob/master/src/main/java/io/github/xjrga/linearprogram/LPModel.java

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to