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

Extreme matrix range [6e-11, 2e+08] in multi-stage energy system MILP — model not solving within 24 hours

回答済み

コメント

3件のコメント

  • Riley Clement
    • Gurobi Staff

    Hi Xinge,

    I would not set Aggregate=2, this will be making the problem worse.  My guess is that it would be better to also leave PreSparsify at its default.  Your other parameter settings look reasonable although ideally would be backed by evidence on smaller models.

    You are correct regarding coefficient stats - 19 orders of magnitude is really bad and I am not surprised that Gurobi is struggling to solve this.  I would recommend reading the following section in our reference manual for a guide on how to address this: https://docs.gurobi.com/projects/optimizer/en/current/concepts/numericguide/tolerances_scaling.html#advanced-user-scaling

    Are you using Python?  If you are not sure where the very large, and very tiny coefficients are coming from then you will likely need to do some model analysis, and this is easiest done in Python.  I can give you code if so.

    We also have an “alpha release” of some scaling functionality in our model-analyzer package:
    https://gurobi-modelanalyzer.readthedocs.io/en/latest/scaling.html

    Since this is an alpha release, it has not yet been published to PyPI.  If you want to try it you will need to install it directly from github:

    pip install git+https://github.com/Gurobi/gurobi-modelanalyzer

    - Riley

     

     

    0
  • Xinge Gao
    • First Comment
    • First Question

    Hi Riley,

    Thank you for your quick reply and all the information.

    I am using Python and would be happy to get the code for finding the small and large coefficients in the matrix range. 

    Also, I am not fully sure I understand the function of Threads correctly. Is it correct to assume a higher number of Threads (e.g. 16) leads to faster solve times for barrier method? Is there a rule of thumb which number of threads should be used for large-scale energy optimization? 

    Kindly,

    Xinge 

    0
  • Riley Clement
    • Gurobi Staff

    Hi Xinge,

    You can use the following code

    import gurobipy as gp
    import numpy as np
    import pandas as pd
    
    m = gp.read("/path/to/model")
    
    col_names = {v.index:v.varname for v in m.getVars()}
    row_names = {c.index:c.constrname for c in m.getConstrs()}
    
    A = m.getA().tocoo()
    df = pd.DataFrame(
        {
            "row": A.row,
            "col": A.col,
            "mag": np.floor(np.log10(abs(A.data))),
        }
    )
    
    column_coefficients = (
        df.groupby("col")["mag"]
        .agg(["min", "max"])
        .eval("range = max-min")
        .eval("name = col.map(@col_names)")
        .set_index("name")
    )
    
    row_coefficients = (
        df.groupby("row")["mag"]
        .agg(["min", "max"])
        .eval("range = max-min")
        .eval("name = row.map(@row_names)")
        .set_index("name")
    )

    The “range” column of the column_coefficients and row_coefficients dataframes will be the most useful information.  Any value above 6 is not ideal.

    You can also use “min” and “max” to find the variables and constraints with small and large coefficients.

    Although barrier often does scale well with parallel threads, it often does so up to a point, and then further threads deteriorates the performance.  Gurobi may not choose to use all the threads which are available, and will report the number it uses in the “Barrier statistics” section of the log.  If it chooses less threads than the number of CPUs on your machine then adding more threads is expected to not help.

    - Riley

     

    0

サインインしてコメントを残してください。