Originally posted by: SystemAdmin
>
>
IloNumVar x = cplex.numVar(lb, ub, IloNumVarType.Float,
"xname");
> This
constructor method allows you to set all the attributes of a variable: its lower and upper
> bounds, its type, and its name. Names are optional in the sense that null strings are
> considered to be valid as well."
>
> What's the meaning of "type"?
Variables can have type Float (double precision real), Int (integer) or Bool (0-1). IloNumVarType is an enumeration that indicates the type of a variable. Think of it as enumerating a particular interface that the object will implement.
>
>
>
> but in java.lang, an interface, for example: cloneable, need to be
implemented It is, but the class (classes?) implementing it are somewhat hidden. (More below.)
>
>
> I just wonder is this interface in ilog is the same as that interface in java API.
Yes, "interface" here has standard Java meaning.
> and an interface can be used by the way as
an object of type IloNumVar >
or one of its extensions; what is the meaning of "Type"? Does it mean that we can create an object implements the interface without defining the class that implements the interface first. it seems IloNumVar is used everywhere more like a class instead of an general instance.
It looks that way, but the appearance is a bit deceptive. Here is my understanding, with the caveat that I could be wrong about it (since I'm not privy to the internal workings of CPLEX). In the C++ API, variables can be freestanding objects that are "owned" by particular environments (which means that multiple models can use the same variables). In the Java API, there are no explicit "environments" (they are created implicitly when you create an instance of IloCplex). As a consequence, variables cannot be freestanding; they have to be "owned" by a specific instance of IloCplex (and cannot be shared across instances). Although I don't recall seeing it stated anywhere, I'm pretty sure that means each variable is a member of the owning IloCplex instance.
Assuming that much is correct, a variable must be an instance of some subclass derived ultimately from the Java Object class, and that subclass implements one of the three variable type interfaces (IloNumVar, IloIntVar, IloSemiContVar). As it turns out, you never need to use the precise subclass itself, just the relevant interface, so CPLEX does not publish the subclass (which might be a private inner class of IloCplex).
You are correct that an interface cannot be instantiated. When you create a variable in the Java API, you create an object which is a member of an instance of IloCplex and implements an interface.
Hope that helps,
Paul
Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
#DecisionOptimization#MathematicalProgramming-General