Hello, I am trying java interop with the choco-solver java library 4.10.18. I run into a problem trying to call a https://javadoc.io/static/org.choco-solver/choco-solver/4.10.18/org.chocosolver.solver/org/chocosolver/solver/constraints/IIntConstraintFactory.html#arithm(org.chocosolver.solver.variables.IntVar,java.lang.String,org.chocosolver.solver.variables.IntVar,java.lang.String,int) with 5 args. There are https://javadoc.io/doc/org.choco-solver/choco-solver/4.10.18/org.chocosolver.solver/org/chocosolver/solver/constraints/IIntConstraintFactory.html#arithm(org.chocosolver.solver.variables.IntVar,java.lang.String,org.chocosolver.solver.variables.IntVar,java.lang.String,org.chocosolver.solver.variables.IntVar) with 5 args so I think I run into an overloading problem (clojure somehow take wrong method?). Error message is Execution error (ClassCastException) at clojure-choco-solver.core/-main (core.clj:11).
class org.chocosolver.solver.constraints.Arithmetic cannot be cast to class [Lorg.chocosolver.solver.constraints.Constraint; (org.chocosolver.solver.constraints.Arithmetic and [Lorg.chocosolver.solver.constraints.Constraint; are in unnamed module of loader 'app') source code follows;
(ns clojure-choco-solver.core
(:import [org.chocosolver.solver Model]
[org.chocosolver.solver.constraints Arithmetic]))
(defn -main
"Demo: Solve x + y = 5 with x, y in 0..5"
[& args]
(let [model (Model. "Simple Addition")
x (.intVar model "x" 0 5)
y (.intVar model "y" 0 5)
^Arithmetic a (.arithm model x "+" y "=" 5)]
(.post model a)
(let [solver (.getSolver model)]
(while (.solve solver)
(println "x =" (.getValue x) ", y =" (.getValue y))))))
The type error indicates it is expecting an array
As you can see I have tried to give a hint with ^Arithmetic but I get the same error anyway
(a type name prefixed with [ is how the jvm indicates an array of that type)
This typically due to varargs
Likely the .post method on model is varargs
cool (.post model (into-array Constraint [a])) worked! thanks3
I have addressed the issue of logging and/or instrumenting multimethods with the tap> mechanism. It is so lightweight it can be added for interactive debug, or left in.