I am trying to use the ojAlgo Java library from Clojure, but I am not able to call the weight method of the Expression class.
To demonstrate it, I have a Leiningen project with this dependency: [org.ojalgo/ojalgo "47.3.1"]
I am trying to do this:
(ns ojalgo-test
(:require [clojure.reflect :as r])
(:import [org.ojalgo.optimisation ExpressionsBasedModel
Expression]
CallExpressionWeight))
(def m (ExpressionsBasedModel.))
;; => #'ojalgo-test/m
(def e (.addExpression m))
;; => #'ojalgo-test/e
(.weight e 1.0) ;; ERROR!
However, the last line fails with the error
- Unhandled java.lang.IllegalArgumentException No matching method weight found taking 1 args for class
org.ojalgo.optimisation.Expression
Question: Why do I get this error and how can I call the weight
method without getting an error?
But what is interesting is that I can write a small Java class to call this method:
import org.ojalgo.optimisation.Expression;
public class CallExpressionWeight {
public static void apply(Expression e, double w) {
e.weight(w);
}
}
And that works:
(CallExpressionWeight/apply e 1.0)
;; => nil
Furthermore, I used the clojure.reflect/reflect
function to look at the methods of my Expression
instance:
(def member-set (set (map :name (:members (r/reflect e)))))
;; => #'ojalgo-test/member-set
(contains? member-set 'setInfeasible)
;; => true
(contains? member-set 'weight)
;; => false
There is something fishy with that weight
method...