[英]invoke cplex variable from an other function in java
How can we invoke cplex (IloCplex cplexx = new IloCplex();) variable from an other function? 我们如何从另一个函数调用cplex(IloCplex cplexx = new IloCplex();)变量? because i need to use it frequantly from other functions but i cant do it because it behaves like a local variable.
因为我需要从其他函数频繁地使用它,但是我不能这样做,因为它的行为类似于局部变量。
Make it a global variable? 使其成为全局变量?
As such: 因此:
public class MyClass{
private IloCplex cplexx;
public MyClass(){
cplexx = new IloCplex();
}
//use cplexx anywhere in MyClass with this.cplexx
}
If you want to use the same Cplex make a getter by adding this method to MyClass: 如果要使用相同的Cplex,请通过将此方法添加到MyClass来获得吸气剂:
public IloCplex getCplexx(){
return this.cplexx;
}
And in other classes you can go like this: 在其他课程中,您可以像这样去:
public class Main{
public static void main(String args[]){
MyClass mine = new MyClass();
mine.getCplexx().solve(); //or some other logic
System.out.println(mine.getCplexx().getObjValue());
}
}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.