GRBCallback.getSolution() for GRBVar[][] array with different inner lengths in Java
回答済みI am using the Java API and I am having some troubles with the GRBCallback method
double[][] getSolution(GRBVar[][] xvars)
documented here https://www.gurobi.com/documentation/9.5/refman/java_cb_getsolution.html
Apparently, there is no constraint on the shape of xvars inner arrays, but if I call getSolution(xvars) when xvars = {{}, { var[1,0] }, {var[2,0], var[2,1]}} (i.e., xvars stores the lower triangular submatrix of a 3x3 matrix), then the returned array is just {{}, {}, {}}. It seems to me that internally the getSolution() method assumes that the size of each xvars[i] array equals xvars[0]. Is it so? Is this the desired/expected behaviour? (I don't think so).
Background: I came across this problem while modifying this Travelling Salesman Problem example https://www.gurobi.com/documentation/9.5/examples/tsp_java.html which stores the same variable twice inside the 'vars' array (i.e. vars[i][j] == vars[j][i]) which is "handy" but actually not needed and leads to a consumption of twice the memory (moreover, it also has the inconvenient to create the variables vars[i][i] that needs to be "turned off" right after being created).
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Lorenzo,
It seems to me that internally the getSolution() method assumes that the size of each xvars[i] array equals xvars[0]. Is it so? Is this the desired/expected behaviour? (I don't think so).
You are correct, the getSolution() method assumes that the sizes of each \(\texttt{xvars[i]}\) array are the same. This is intended behavior to not over-complicate the API in terms of array management.
Please note that you can always use the \(\texttt{double[] GetSolution (GRBVar[] xvars)}\) version with a self defined array holding the differently sized variable arrays to minimize memory requirements. I agree that it would be more convenient to have a function handling this and thus, we might consider adding such a convenience method in a future release.
Background: I came across this problem while modifying this Travelling Salesman Problem example https://www.gurobi.com/documentation/9.5/examples/tsp_java.html which stores the same variable twice inside the 'vars' array (i.e. vars[i][j] == vars[j][i]) which is "handy" but actually not needed and leads to a consumption of twice the memory (moreover, it also has the inconvenient to create the variables vars[i][i] that needs to be "turned off" right after being created).
The idea of using the vars[][] array there is that it makes the example easier to extend to directed edges, or any other graph problem allowing self-loops (vars[i][i] != 0). The example is not meant to be the most memory efficient but rather to present the API and the possibilities it provides.
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント