def run(self): ctx = tzmq.Context() socket_supervisor = ctx.socket(tzmq.REP) socket_supervisor.connect('ipc:///tmp/supervisor_task.ipc') data = unserialize(socket_supervisor.recv()) try: auction_id, scenario, options = data convertToNamedTuples(scenario) res = self._solve(scenario, options) socket_supervisor.send(serialize([None, auction_id, res])) except Exception, err: logging.error('could not solve: %d. %s' % (auction_id, traceback.format_exc())) socket_supervisor.send(serialize(['Error: %s' % err, auction_id, None]))
parser.add_option('--time-limit-gwd',dest='time_limit_gwd', type='int', default='20', help='the time limit for the initial winner determination problem') parser.add_option('--time-limit',dest='time_limit', type='int', default='20', help='the time limit for all problems but the initial winner determination problem') parser.add_option('--epgap',dest='epgap', type='float', default=None, help='the epgap used for all problems') parser.add_option('--offset',dest='offset', type='int', default=0, help='the scenario offset used') for option in parser.option_list: if option.default != ("NO", "DEFAULT"): option.help += (" " if option.help else "") + "[default: %default]" if sys.stdin.isatty(): print parser.format_help() sys.exit() # parse scenario and options scenarios = json.decode(sys.stdin.read()) options = parser.parse_args()[0] scenario = scenarios[options.offset] convertToNamedTuples(scenario) slots, bidder_infos = scenario # create processor object and set values proc = TvAuctionProcessor() if options.price_vector=='vcg': proc.vcgClass = Vcg elif options.price_vector=='zero': proc.vcgClass = Zero if options.core_algorithm=='trim': proc.core_algorithm = CorePricing.TRIM_VALUES elif options.core_algorithm=='switch': proc.core_algorithm = CorePricing.SWITCH_COALITIONS elif options.core_algorithm=='reuse': proc.core_algorithm = CorePricing.REUSE_COALITIONS # solve and print res = proc.solve(slots, bidder_infos, options.time_limit or None, options.time_limit_gwd or None, options.epgap or None) print json.encode(res)