Commit 961df375 by Peter Wittek

### Primals are parsed in the SDPA wrapper

parent f20d109f
 ... ... @@ -5980,6 +5980,7 @@ class Problem(object): # call the solver # #--------------------# import time import os from subprocess import call tstart = time.time() if self.options['verbose']>=1: ... ... @@ -5993,32 +5994,6 @@ class Problem(object): #-----------------------# # retrieve the solution # #-----------------------# def parse_solution_matrix(iterator): solution_matrix = [] while True: sol_mat = None in_matrix = False i = 0 for row in iterator: if row.find('}') < 0: continue if row.startswith('}'): break if row.find('{') != row.rfind('{'): in_matrix = True numbers = row[row.rfind('{')+1:row.find('}')].strip().split(',') if sol_mat is None: sol_mat = np.empty((len(numbers), len(numbers))) for j, number in enumerate(numbers): sol_mat[i, j] = float(number) if row.find('}') != row.rfind('}') or not in_matrix: break i += 1 solution_matrix.append(sol_mat) if row.startswith('}'): break return solution_matrix file_ = open(self.sdpa_out_filename, 'r') for line in file_: if line.find("phase.value") > -1: ... ... @@ -6032,12 +6007,10 @@ class Problem(object): status='unknown' if line.find("objValPrimal") > -1: obj = float((line.split())[2]) if line.find("xMat =") > -1: x_mat = parse_solution_matrix(file_) if line.find("yMat =") > -1: y_mat = parse_solution_matrix(file_) if line.find("xVec =") > -1: line = six.next(file_) x_vec = [float(x) for x in line[line.rfind('{')+1:line.find('}')].strip().split(',')] file_.close() import os os.remove(self.sdpa_dats_filename) os.remove(self.sdpa_out_filename) ... ... @@ -6045,8 +6018,19 @@ class Problem(object): if self.options['verbose']>0: print('SDPA solution status: '+status) primals, duals = {}, {} # Convert primal solution primals = {} for var in self.variables.keys(): si=self.variables[var].startIndex ei=self.variables[var].endIndex value = x_vec[si:ei] if self.variables[var].vtype in ('symmetric',): value=svecm1(cvx.matrix(value)) #value was the svec #representation of X primals[var]=cvx.matrix(value, self.variables[var].size) # Dual solution is not parsed yet duals = [] #------------------# # return statement # #------------------# ... ... @@ -6621,7 +6605,6 @@ class Problem(object): self.cvxoptVars['A'] = P*self.cvxoptVars['A'] self.cvxoptVars['b'] = P*self.cvxoptVars['b'] c = self.cvxoptVars['c'] #-----------------------------------------------------------# # make A,B,and blockstruct. # # This code is a modification of the conelp function in smcp# ... ... @@ -6661,7 +6644,8 @@ class Problem(object): #open file f = open(filename, 'w') f.write('"file '+filename+' generated by picos"\n') print('writing problem in '+filename+'...') if self.options['verbose']>=1: print('writing problem in '+filename+'...') f.write(str(self.numberOfVars)+' = number of vars\n') f.write(str(len(P_blockstruct))+' = number of blocs\n') #bloc structure ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!