def if_feasible(self, z_new, lower_limit): L = self.L if (any(z_new[0:2 * self.L] <= lower_limit)): # some g1 less equan then zero return False for p in range(0, self.L): # ph index_start = 2 * L + int(p) * 4 * L * L index_end = 2 * L + int(p + 1) * 4 * L * L zmatrix = transform_vec_to_matrix( z_new[index_start:index_end], 2 * L) - lower_limit * np.identity(2 * L, dtype=np.float32) try: np.linalg.cholesky(zmatrix) except: #if cholesky failed, then fmatrix is not positive definite return False for p in range(0, self.L): # pair1 index_start = 2 * L + 4 * L * L * L + int(p) * L * L index_end = 2 * L + 4 * L * L * L + int(p + 1) * L * L zmatrix = transform_vec_to_matrix( z_new[index_start:index_end], L) - lower_limit * np.identity(L, dtype=np.float32) try: np.linalg.cholesky(zmatrix) except: #if cholesky failed, then fmatrix is not positive definite return False for p in range(0, self.L): # pair2 index_start = 2 * L + 5 * L * L * L + int(p) * L * L index_end = 2 * L + 5 * L * L * L + int(p + 1) * L * L zmatrix = transform_vec_to_matrix( z_new[index_start:index_end], L) - lower_limit * np.identity(L, dtype=np.float32) try: np.linalg.cholesky(zmatrix) except: #if cholesky failed, then fmatrix is not positive definite return False return True
def generate_two_ph_dual_zmatrix(self, p): L = self.L index_start = 2 * L + int(p) * 4 * L * L index_end = 2 * L + int(p + 1) * 4 * L * L zmatrix = transform_vec_to_matrix(self.vec_z[index_start:index_end], 2 * self.L) return zmatrix
def generate_two_pair1_primal_matrix(self,p): L = self.L index_start = 2*L + 4*L*L*L + int(p)*L*L index_end = 2*L + 4*L*L*L + int(p+1)*L*L fmatrix = transform_vec_to_matrix( self.vec_x[index_start:index_end], self.L) return fmatrix
def initialization(self): L = self.L mu = 0.1 linear_eq_A = np.dot(self.const_var.mat_C, np.transpose(self.const_var.mat_C)) linear_eq_b = -self.const_var.vec_b - np.dot(self.const_var.mat_C, self.vec_ham) self.var_y = solve(linear_eq_A, linear_eq_b) temp_x = -np.dot(np.transpose(self.const_var.mat_C), self.var_y) - self.vec_ham self.var_y = self.var_y temp_x = temp_x for i in range(0, 2 * L): if (temp_x[i] > 0.0): self.primal_var.vec_x[i] = temp_x[i] self.dual_var.vec_z[i] = mu / temp_x[i] else: self.primal_var.vec_x[i] = 1.0 self.dual_var.vec_z[i] = mu for p in range(0, L): index_st = 2 * L + p * (L * L) * 4 index_en = index_st + 4 * L * L temp_mat = transform_vec_to_matrix(temp_x[index_st:index_en], 2 * L) eig = eigvals(temp_mat) eig_min = np.min(eig) if (eig_min > self.truncation): self.primal_var.vec_x[index_st:index_en] = temp_x[ index_st:index_en].copy() else: temp_mat = temp_mat + (1.0 + abs(eig_min)) * np.identity( 2 * L, dtype=np.complex64) self.primal_var.vec_x[index_st:index_en] = vectorize( temp_mat, 2 * L) self.dual_var.vec_z[index_st:index_en] = vectorize( mu * inv(temp_mat), 2 * L) for p in range(0, L): index_st = 2 * L + 4 * L * L * L + p * (L * L) index_en = index_st + (L * L) temp_mat = transform_vec_to_matrix(temp_x[index_st:index_en], L) eig = eigvals(temp_mat) eig_min = np.min(eig) if (eig_min > self.truncation): self.primal_var.vec_x[index_st:index_en] = temp_x[ index_st:index_en].copy() else: temp_mat = temp_mat + (1.0 + abs(eig_min)) * np.identity( L, dtype=np.complex64) self.primal_var.vec_x[index_st:index_en] = vectorize( temp_mat, L) self.dual_var.vec_z[index_st:index_en] = vectorize( mu * inv(temp_mat), L) for p in range(0, L): index_st = 2 * L + 5 * L * L * L + p * (L * L) index_en = index_st + (L * L) temp_mat = transform_vec_to_matrix(temp_x[index_st:index_en], L) eig = eigvals(temp_mat) eig_min = np.min(eig) if (eig_min > self.truncation): self.primal_var.vec_x[index_st:index_en] = temp_x[ index_st:index_en].copy() else: temp_mat = temp_mat + (1.0 + abs(eig_min)) * np.identity( L, dtype=np.complex64) self.primal_var.vec_x[index_st:index_en] = vectorize( temp_mat, L) self.dual_var.vec_z[index_st:index_en] = vectorize( mu * inv(temp_mat), L) rx = self.vec_ham + np.dot(np.transpose(self.const_var.mat_C), (self.var_y)) - (self.dual_var.vec_z) ry = -self.const_var.vec_b + np.dot(self.const_var.mat_C, (self.primal_var.vec_x))