Changeset 2030


Ignore:
Timestamp:
Dec 22, 2009 4:55:52 PM (12 years ago)
Author:
jwatson
Message:

Added a "solve_all_instances" utility function to the solver manager library. This function takes three arguments:

  • a solver manager
  • a solver
  • a list of instances

The routine applies the supplied solver (through the supplied solver manager) to each of the instances, retreives the results, loads them into the corresponding instance, and performs a barrier synchronization - returning when all instance solves are complete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/trunk/coopr/opt/parallel/manager.py

    r1960 r2030  
    1010
    1111
    12 __all__ = ['ActionManagerError', 'ActionHandle', 'AsynchronousActionManager', 'ActionStatus', 'FailedActionHandle']
     12__all__ = ['ActionManagerError', 'ActionHandle', 'AsynchronousActionManager', 'ActionStatus', 'FailedActionHandle', 'solve_all_instances']
    1313
    1414from pyutilib.enum import Enum
    1515
    16 
    1716ActionStatus = Enum('done', 'error', 'queued', 'executing', 'unknown')
    1817
     18# a simple utility to, given a solver manager and a solver, apply the solver to
     19# each problem instance, load the results into the instance, and execute a barrier
     20# synchronization.
     21def solve_all_instances(solver_manager, solver, instances):
     22   action_handles = []
     23   instance_map = {}
     24   for instance in instances:
     25      action_handle = solver_manager.queue(instance, opt=solver)
     26      instance_map[action_handle] = instance
     27      action_handles.append(action_handle)
     28   solver_manager.wait_all(action_handles)
     29   for action_handle in action_handles:
     30      results = solver_manager.get_results(action_handle)
     31      instance_map[action_handle].load(results)
     32   return
    1933
    2034class ActionManagerError(Exception):
Note: See TracChangeset for help on using the changeset viewer.