def fit(self, time_limit=None, node_limit=None, display_flag=False): if self._mip is None: return self.infeasible_info mip = self.mip mip = set_cpx_display_options(mip, display_mip=False, display_lp=display_flag, display_parameters=display_flag) # update time limit if time_limit is not None: mip = set_mip_time_limit(mip, time_limit) if node_limit is not None: mip = set_mip_node_limit(mip, node_limit) # solve start_time = mip.get_time() mip.solve() end_time = mip.get_time() - start_time info = self.solution_info info['runtime'] = end_time # assert self._check_solution(info) return info
def populate(self, total_items=10, time_limit=None, node_limit=None, display_flag=False, enumeration_type='distinct_subsets'): mip = self.mip mip = set_cpx_display_options(mip, display_mip=False, display_lp=display_flag, display_parameters=display_flag) # update time limit if time_limit is not None: mip = set_mip_time_limit(mip, time_limit) if node_limit is not None: mip = set_mip_node_limit(mip, node_limit) if enumeration_type == 'mutually_exclusive': remove_solution = self.remove_all_features else: remove_solution = self.remove_feature_combination # enumerate soluitions k = 0 all_info = [] populate_start_time = mip.get_time() while k < total_items: # solve mip start_time = mip.get_time() mip.solve() run_time = mip.get_time() - start_time info = self.solution_info info['runtime'] = run_time if not info['feasible']: if self.print_flag: print('recovered all minimum-cost items') break all_info.append(info) remove_solution() k += 1 if self.print_flag: print('mined %d items in %1.1f seconds' % (k, mip.get_time() - populate_start_time)) return all_info
def __init__(self, action_set, x = None, **kwargs): """ :param x: vector of input variables for person x :param intercept: intercept value of score function :param coefs: coefficients of score function :param action_set: action set :param params: parameters for flipset form/flipset generation (e.g. type of cost function to use / max items etc.) """ # initialize Cplex MIP self._cpx_parameters = kwargs.get('cplex_parameters', self._default_cplex_parameters) self._set_mip_time_limit = set_cpx_time_limit self._set_mip_node_limit = set_cpx_node_limit self._set_mip_display = lambda mip, flag: set_cpx_display_options(mip, display_lp = flag, display_mip = flag, display_parameters = flag) ## initialize base class super().__init__(action_set = action_set, x = x, **kwargs)