メインコンテンツへスキップ

GRBCallback.getSolution() for GRBVar[][] array with different inner lengths in Java

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Jaromił Najman
    • Gurobi Staff

    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

投稿コメントは受け付けていません。