Beispiel #1
0
  def reset(self):
    self._reset_next_step = False
    self._ep_return = 0
    self._n_steps = 0
    # start from src node.
    self._curr_node = self._src_node
    self._graph_features = copy.deepcopy(self._reset_graph_features)

    return restart(self._observation())
Beispiel #2
0
  def reset_solution(self, sol, obj_val):
    # call at the beginning of a local move.
    # assert self._globals[Env.GLOBAL_UNFIX_LEFT] == self.k
    self._change_sol(sol, obj_val, sol, obj_val)

    self._best_quality = self._primal_gap(obj_val)
    self._final_quality = self._best_quality
    self._qualities = [self._best_quality]
    return restart(self._observation())
Beispiel #3
0
 def reset(self):
     if self._reset_next_step:
         self._prev_ep_return = self._ep_return
         self._ep_return = 0
         self._n_steps = 0
         # start from src node.
         self._curr_node = self._src_node
         # reset features
         self._graph_features = copy.deepcopy(self._fixed_graph_features)
         # path collected so far
         self._path = [self._curr_node]
         self._reset_next_step = False
     return restart(self._observation())
Beispiel #4
0
    def reset(self):
        # fix the graph for a few episodes to reduce load on the disk while loading datasets.
        if self._n_resets % self._sample_every_n_resets == 0:
            self.milp, self._sol, self._obj = self._sample()
            self.mip = SCIPMIPInstance.fromMIPInstance(self.milp.mip)
            # clean up previous scip model
            if hasattr(self, '_sub_mip_model'):
                del_scip_model(self._sub_mip_model)
            self._sub_mip_model = self.mip.get_scip_model()
        sol, obj, mip = self._sol, self._obj, self.mip
        c_f, e_f, v_f = load_pickled_features(self._dataset,
                                              self._dataset_type,
                                              self._milp_choice)
        self._var_names = var_names = list(
            map(lambda v: v.name.lstrip('t_'), mip.vars))
        # call init_features before init_ds
        self._init_features(var_names, v_f)
        self._init_ds()
        self._constraint_nodes = np.float32(c_f['values'])
        self._change_sol(sol, obj, sol, obj)
        self._best_quality = self._primal_gap(obj)
        self._final_quality = self._best_quality
        self._qualities = [self._best_quality]

        self._unfixed_variables = filter(lambda v: v.vtype() == 'CONTINUOUS',
                                         mip.vars)
        self._unfixed_variables = set(
            map(lambda v: v.name.lstrip('t_'), self._unfixed_variables))
        self._vars_unfixed_so_far = []

        # static features computed only once per episode.
        if self.config.make_obs_for_graphnet:
            raise Exception('Not yet supported!')
            self._static_graph_features = self._encode_static_graph_features()
        elif self.config.make_obs_for_bipartite_graphnet:
            self._static_graph_features = self._encode_static_bipartite_graph_features(
                e_f)
        self._n_resets += 1
        return restart(self._observation())
Beispiel #5
0
 def reset(self):
     self._reset_next_step = False
     self._features = np.float32(np.random.randint(0, 2, size=(2, )))
     return restart(self._observation())