def update_y_z_w_u_v()

in optimizer.py [0:0]


    def update_y_z_w_u_v(self, N, M, binary=True, log_dir=None):
        os.makedirs(log_dir, exist_ok=True)
        file = open(os.path.join(log_dir, "log.txt"), 'a')

        old_N = len(self.y) if hasattr(self, 'y') else 0
        old_M = len(self.z) if hasattr(self, 'z') else 0
        print("old N, M", old_N, old_M)

        start = time.time()
        print("init y, z, w", file=file, flush=True)

        self.model.remove(self.y)
        self.y = self.model.addVars(N, vtype=GRB.BINARY, name='y')

        # remove replication constr because db_table can change
        self.model.remove(self.rep_constr)
        self.rep_constr = []

        self.model.remove(self.z)
        self.model.remove(self.w)
        self.z = self.model.addVars(M, vtype=GRB.BINARY, name='z')
        self.w = self.model.addVars(M, vtype=GRB.BINARY, name='w')
        for j in range(M):
            self.model.addConstr(self.z[j] + self.w[j] <= 1, name=f'zw_{j}')

        if self.rep_threshold is not None:
            for key in self.rep_list:
                # if self.unique_db_tables[key] is not None:
                if key in self.unique_db_tables:
                    j = self.unique_db_tables[key]
                    self.rep_constr.append(self.model.addConstr(self.z[j] == 0, name=f'z_{j}_0'))
                    self.rep_constr.append(self.model.addConstr(self.w[j] == 0, name=f'w_{j}_0'))
                else:
                    print("Warning: replicated table not found in unique_db_tables", key)

        print_time(start, time.time(), "y, z, w created", file=file)

        start = time.time()
        print("If sample rate < 1, progress is usually under-estimated, nothing wrong happened")
        print("init u, v", file=file, flush=True)
        # Recover u, v complete
        self.model.remove(self.u)
        self.model.remove(self.v)
        self.u = {}
        self.v = {}

        replicated_indices = [self.unique_db_tables[key] for key in self.rep_list if key in self.unique_db_tables]
        for j in range(M):
            if j in replicated_indices:
                continue
            job_ids = self.adj_list_input[j].keys()
            for i in job_ids:
                self.u[(i, j)] = self.model.addVar(vtype=GRB.BINARY, name=f'u_{i}_{j}')
                self.v[(i, j)] = self.model.addVar(vtype=GRB.BINARY, name=f'v_{i}_{j}')

        print_time(start, time.time(), "u, v created", file=file)
        file.close()
        # Update model to integrate new variables
        self.model.update()
        print("updated to new N, M", len(self.y), len(self.z), "=", len(self.w))
        print("updated to new U, V", len(self.u), len(self.v))