[OS] Java: how to start?

Olivier Cailloux olivier.cailloux at ecp.fr
Mon Feb 1 08:02:38 EST 2010


Thanks to everybody for the informations and examples. I will look at 
that more carefully in the following days.
Olivier


Kipp Martin a écrit :
> Hi Olivier:
>
>
>> 1) Java code to use.
>> I searched for java binaries (i.e., .jar libraries) but I have been 
>> unable to find them. Indeed either distributing OSCommon.jar in the 
>> binaries download as you suggest, or saying something about how to 
>> access COIN-OR implementations from Java in the user's manual would 
>> be useful for your Java users, I feel.
>
> Yes, I agree, we need to make things more usable for Java users.
>
>>
>> 2) About the input file not accepted by OSSolverService binary.
>> Kipp Martin tells me (I post my reply to the list so that Google 
>> might reference it) that the problems comes from that version (1.3.1, 
>> or 2.0.0, I'm a bit lost with the versioning scheme) not recognizing the 
>
> With regard to version numbers, CoinAll is really a meta-project that 
> consists of numerous COIN-OR projects (for example OS). Each of these 
> projects are at different stages of development and hence have 
> different  version numbers.
>
>
>>
>> 3) Building the OSiL file from Java.
>> Using the Java source from OSCommon, I have been able to build the 
>> OSiL input file without problem (except for the <instanceHeader/> 
>> part). Here is a working sample for interested users. (I added a 
>> setInstanceName call so that the instanceHeader tag does not trigger 
>> the bug any more.)
>> ----
>>     final OSInstance inst = new OSInstance();
>>     inst.setInstanceName("firstProfile");
>>     inst.setVariableNumber(4);
>>     inst.addVariable(0, "gjb2", 0, Double.POSITIVE_INFINITY, 'C');
>>     inst.addVariable(1, "gjb3", 0, Double.POSITIVE_INFINITY, 'C');
>>     inst.addVariable(2, "s2", 0, Double.POSITIVE_INFINITY, 'C');
>>     inst.addVariable(3, "s3", 0, Double.POSITIVE_INFINITY, 'C');
>>
>>     inst.setObjectiveNumber(1);
>>     final SparseVector v = new SparseVector();
>>     v.indexes = new int[] { 2, 3 };
>>     v.values = new double[] { 1, 1 };
>>     inst.addObjective(-1, "sumofslack", "min", 0d, 1d, v);
>>     inst.setConstraintNumber(2);
>>     final boolean conSet = inst.addConstraint(0, "lowCat", 3d, 3d, 0d);
>>     System.out.println(conSet);
>>     final boolean con1Set = inst.addConstraint(1, "highCat", 3.1d, 
>> 3.1d, 0d);
>>     System.out.println(con1Set);
>>     final boolean coeffSet = inst.setLinearConstraintCoefficients(4, 
>> false, new double[] { 1, 1, 1, 1 }, 0, 3,
>>         new int[] { 0, 2, 1, 3 }, 0, 3, new int[] { 0, 2, 4 }, 0, 2);
>>     System.out.println(coeffSet);
>>     final String osil = inst.writeOSiL();
>>     IOUtil.writeStringToFile(osil, "osilFirstProfile.xml");
>> ----
>
> This is very nice!  Would you send me the Java file?
>
>>
>> I thought I would find in the OSSolver folder the way to call the 
>> solvers from Java. But as mentioned previously, I can't make it call 
>> a local binary, it wants to call a (possibly local, i.e. running on 
>> 127.0.0.1) web service. Should I write myself the code to build a 
>> command line calling OSSolverService, or can I reuse the code you 
>> mention is working for you? Also, Jun Ma, you suggest to use only the 
>> OSCommon source folder, does that imply that other parts are 
>> considered not ready / unstable / unusable?
>
> You can reuse our code. What you need to call the C++ OSSolverService 
> is in the OSCommon folder. In particular, please see
>
> OSjava/OSCommon/src/org/optimizationservices/oscommon/util/StandardOSSolver.java 
>
>
> and
>
> OSjava/OSCommon/src/org/optimizationservices/oscommon/util/ProcessUtil.java 
>
>
> Inside StandardOSSolver.java you will see line 105
>
> ProcessUtil.launchAndWaitForFinish(sSolverPath + " " + sArguments);
>
> This is the line where we are launching the OSSolverService C++ 
> executable and passing the arguments such as -osil example.osil. It is 
> using the launchAndWaitForFinish method in ProcessUtil.java.
>
> Does this help?
>
>
>



More information about the OS mailing list