Termination criteria set up in PDLP

383 views
Skip to first unread message

LZhang

unread,
Oct 4, 2022, 9:17:48 PM10/4/22
to or-tools-discuss
Hi team,

I've been using PDLP with python. May I ask how to set up the termination criteria (eps_optimal_absolute) in python code?  May I ask in which line below can I insert such an argument? Thanks 

My sample code was like:
solver = pywraplp.Solver.CreateSolver('PDLP')
    if not solver:
        return

    infinity = solver.infinity()
   
    m = len(p)
    n = len(r)
    # create ones vector
    onesm = np.ones(m)
    onesn = np.ones(n)
   
    #start_time = time.time()
    x = {}
    for i in range(m):
        for j in range(n):
            x[i,j] = solver.NumVar(0.0, 1.0, 'x'+str(i)+str(j))
   
    print('Number of variables =', solver.NumVariables())

    # set up the obj
    rev = 0
    for i in range(m):
        for j in range(n):
            rev += p[i]*x[i,j]*v[j]
   
    # set up the constraint
    # relevance
    rel = 0
    for i in range(m):
        for j in range(n):
            rel += p[i]*x[i,j]*r[j]
    solver.Add(rel <= lamb * a)
   
    # row sum
    for i in range(m):
        row_sum = 0
        for j in range(n):
            row_sum += x[i,j]
        solver.Add(row_sum <= 1)
    # column sum
    for j in range(n):
        column_sum = 0
        for i in range(m):
            column_sum += x[i,j]
        solver.Add(column_sum <= 1)

    solver.Maximize(rev)

    status = solver.Solve()

David Applegate

unread,
Oct 5, 2022, 12:42:19 PM10/5/22
to or-tools-discuss
The termination criteria are part of the "solver specific parameters", and can be set using solver.SetSolverSpecificParametersAsString(). For example,
    solver.SetSolverSpecificParamtersAsString('termination_criteria {eps_optimal_absolute: 1e-4}')
The parameters that can be specified for PDLP are described in https://github.com/google/or-tools/blob/stable/ortools/pdlp/solvers.proto

Miles Lubin

unread,
Oct 5, 2022, 10:31:31 PM10/5/22
to or-tools-discuss
For posterity, it's unlikely that you'd want to change only eps_optimal_absolute and not eps_optimal_relative. You can set both with:
  solver.SetSolverSpecificParamtersAsString('termination_criteria {eps_optimal_absolute: 1e-4 eps_optimal_relative: 1e-4}')
See the .proto file that David linked for the definition of these parameters.

LZhang

unread,
Oct 6, 2022, 4:37:29 AM10/6/22
to or-tools-discuss
Thanks a lot!!!
Reply all
Reply to author
Forward
0 new messages