Bonjour à tous,
Choco is a bsd licenced java constraint programming framework.
I use it from some (litle) project and for (french) teaching.
The course is finished, but I consider to switch from java
to JRuby next year. So I have to convert all java code to JRuby
and see if it is possible (all java syntax, performances for callback
methods, …).
But I’ve currently problem while calling static method
from the toplevel class “choco.Choco”.
Il also like to import all static methods as in java:
import static choco.Choco.*;
I’m trying to port the following java code to jruby
import choco.cp.model.CPModel;
import choco.kernel.model.Model;
import choco.kernel.model.variables.integer.IntegerVariable;
…
// import static choco.Choco.*;
import choco.Choco;
public class Mini {
public static void main(String[] args) {
Model m = new CPModel();
// IntegerVariable v1 = makeIntVar("v1", 1, 5, "cp:enum");
IntegerVariable v1 = Choco.makeIntVar("v1", 1, 5,"cp:enum");
m.addVariable(v1);
...
}
}
I write the following JRuby code:
#!/usr/bin/env jruby
require ENV[‘CHOCO_TEST_JAR_NEW’]
require “java”
include_class “choco.cp.model.CPModel”
include_class “choco.kernel.model.Model”
include_class “choco.kernel.model.variables.integer.IntegerVariable”
…
include_class “choco.Choco”
import choco.Choco
How to import static methodss from the choco.Choco class?
class Mini
def initialize args
model = CPModel.new;
# v1 = Choco.makeIntVar "v1", 1, 5, "cp:enum"
# # v1 = Choco::makeIntVar "v1", 1, 5, "cp:enum"
# # v2 = Choco::makeIntVar "v2", 1, 5, "cp:bound"
v1 = Choco::makeIntVar "v1", 1, 5, "cp:enum"
model.addVariable v1
...
end
end
But the following error occurs:
/…/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/
object.rb:116:
in `initialize’: no makeIntVar with arguments matching
[class org.jruby.RubyString, class org.jruby.RubyFixnum,
class org.jruby.RubyFixnum, class org.jruby.RubyString]
on object Java::Choco::Choco (NameError)
from ./Mini.new_api_bad.rb:169
Thank you for your work on Jruby!
– Maurice
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email