Can the CP solver be initialised at a specific point?

前端 未结 1 1870
暗喜
暗喜 2021-01-13 05:46

I am using the CP-Sat solver to optimise a timetable I am making. However, this now takes a long time to solve. Is it possible to seed the solver with an old result, to act

1条回答
  •  被撕碎了的回忆
    2021-01-13 06:21

    Take a look at this solution hinting example:

    • https://github.com/google/or-tools/blob/stable/ortools/sat/doc/model.md#solution-hinting
    num_vals = 3
    x = model.NewIntVar(0, num_vals - 1, 'x')
    y = model.NewIntVar(0, num_vals - 1, 'y')
    z = model.NewIntVar(0, num_vals - 1, 'z')
    
    model.Add(x != y)
    
    model.Maximize(x + 2 * y + 3 * z)
    
    # Solution hinting: x <- 1, y <- 2
    model.AddHint(x, 1)
    model.AddHint(y, 2)
    

    Edit: you should also try to

    • Reduce the amount of variables.
    • Reduce the domain of the integer variables.
    • Run the solver with multiples threads usingsolver.parameters.num_search_workers = 8.
    • Prefer boolean over integer variables/contraints.
    • Set redundant constraints and/or symmetry breaking constraints.
    • Segregate your problem and merge the results.

    0 讨论(0)
提交回复
热议问题