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

Creating an array takes lots of time

ユーザーの入力を待っています。

コメント

6件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Ronald van der Velden
    • Gurobi Staff

    Hi Betül,

    Thanks for posting on the forum! This seems to be a general performance issue unrelated to Gurobi, unless I'm missing something? Nevertheless I'm curious what the magnitude of J and L is here, since the total number of operations is O(I*M*T*J*L) those might help explain the slowness. Also, is your code written in C#? And what is the type of c and ycap - are they simple multidimensional arrays of type int[,] and int[,,,] as well?

    Kind regards,
    Ronald

    0
  • Betul Kayisoglu
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Ronald, it seems it is not related with Gurobi you are right, but I have trouble with constructing the model so maybe I thought it can be related with Gurobi. Yes I am using c#.

    In fact I also coded the model on gams and I have cplex licence on gams, I am solving the same model in seconds 

    c and ycap are simple multidimensional arrays of type int[,] and int[,,,] as well.

     

    0
  • Ronald van der Velden
    • Gurobi Staff

    Interesting! Matrix multiplication in GAMS might be more efficient than "raw" C# - indeed this has nothing to do with the solver being used, whether that's Gurobi or CPLEX. But I'm still curious to see what can be done here :-)

    • It would still be good to know the size of J and L.
    • Also, I can imagine c and/or ycap are sparse, e.g. they contain many zeros. In this case, many of the operations done by .NET are effectively "useless". In that case I would go back to the source of the numbers for c and ycap and think of a different datastructure that would allow a more efficient calculation.
    • Finally, you can always use multithreading to speed this calculation up. C# has low-level (e.g. Thread class) and more high-level (e.g. Task class, or even the Parallel.For options) features that could help you.
    0
  • Betul Kayisoglu
    • Gurobi-versary
    • First Comment
    • First Question

    you are probably right, i am new with Gurobi and wondered if it is special for that.

    * size of j and l are 225 both.

    * yes you are right with this prediction, there are so many zeros e.g. in c there are 225*3038 elements and only 3038 of them have values where the rest is all zero. do you have any suggestion for the different data structure?

    0
  • Ronald van der Velden
    • Gurobi Staff

    in c there are 225*3038 elements and only 3038 of them have values

    I guess for every i there is exactly one l with a non-zero value? In that case:

    • You don't need the inner-most loop iterating over all l , since only one is relevant
    • c[,] could be one-dimensional instead
    • You would need a dictionary that, for each i, gives you the corresponding l

    Does that help? In theory it would give you a ~225x speedup to start with. You might be able to spot similar opportunities if ycap also has certain patterns.

    0

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