49 def identity (self, size ) : -> 50 return numpy. _init_ ( ) 45 46 def name (self ) : /Users/mohameddaoudi/opt/anaconda2/lib/python2.7/site-packages/cvxpy/interface/numpy_interface/ndarray_interface.pyc in const_to_matrix (self, value, convert_scalars) 48 # Return an identity matrix. is_matrix ( ) : /Users/mohameddaoudi/opt/anaconda2/lib/python2.7/site-packages/cvxpy/expressions/expression.pyc in cast_to_const (expr) /Users/mohameddaoudi/opt/anaconda2/lib/python2.7/site-packages/cvxpy/expressions/constants/constant.pyc in _init_ (self, value) 42 self. T ,X ) ,Z1 ), "nuc" ) ) 22 23 #problem = cp.Problem(objective) /Users/mohameddaoudi/opt/anaconda2/lib/python2.7/site-packages/cvxpy/atoms/norm.pyc in norm (x, p, axis) 45 return normNuc (x ) 46 elif p = "fro" : -> 47 return pnorm (x, 2, axis ) 48 elif p = 2 : 49 if axis is None and x. Smallest eigenvalue -7.ValueError Traceback (most recent call last) Though this gives the correct grid cell weights - gridW, the optimizer is not able to Minimize ( minimized distance is inf ) when the weight constraint is added like: constraints = I found a way to make CVXPY compare values and then generate an index. X: # Wrong values printed - Only grid number 0 should have all the nodes Prob = cvxp.Problem(cvxp.Minimize(objectiveX+objectiveY), constraints) #objectiveY = (1/2)*cvxp.quad_form(locY, cvxp.Parameter(shape=cellLP.shape, value=cellLP, PSD=True)) #objectiveX = (1/2)*cvxp.quad_form(locX, cvxp.Parameter(shape=cellLP.shape, value=cellLP, PSD=True)) ObjectiveY = (1/2)*cvxp.quad_form(locY,cellLP) ObjectiveX = (1/2)*cvxp.quad_form(locX,cellLP) W, v = np.linalg.eig(cellLP) # eigen decomposition # Some workaround if not positive semi definiteĬellLP = 0.5*(cellLP+cellLP.T) # make Q symmetric NodesInGridCells = cvxp.Variable(shape=(num_nodes.value,num_grid_cells.value)) #Number of nodes in each grid cell - num_nodes x num_grid_cells matrix GridWt = cvxp.Variable(num_grid_cells.value, pos=True) # Variable to store sum of node weights in a grid cell LocY = cvxp.Variable(num_nodes.value,pos=True) LocX = cvxp.Variable(num_nodes.value,pos=True) GridCapacity = cvxp.Parameter(shape=num_grid_cells.value, value=gridCellCapacities, nonneg=True)ĬellConnectivity = np.matrix(,ĬellWeightedDeg = np.matrix(,ĬellLP = cellWeightedDeg - cellConnectivity # created a Variable intialized with above Max_Y = cvxp.Parameter(nonneg=True,value=(num_grid_cells.value/3)) Max_X = cvxp.Parameter(nonneg=True, value=(num_grid_cells.value/2)) Num_grid_cells = cvxp.Parameter(nonneg=True,value=6) Num_nodes = cvxp.Parameter(nonneg=True,value=10) # E.g graph - 10 nodes with connectivity matrix # once I get the grid cell number issue fixed # Will deal with maximizing grid cell link capacity objective function later # subject to the constraint that number of nodes in a grid cell # such that the total euclidean distance is minimized # place them on a grid of cells which have a link capacity, # Given a set of nodes and weighted edges, The last print line output is expected to show all the nodes are in only grid cell 0. Line 97 (gn = gridNum) and 99 seem to have an issue( highlighted by PROBLEM comment. Sample graph of 10 nodes with weighted edge matrix. When I try to convert the node locations to a grid number with an expression and try to use the elements of the expression vector as an array index ( so that I can sum up all node weights in that grid cell), CVXPY does not seem to work. I am trying to use CVXPY to frame the model as a convex problem of weighted edge length minimization and optimize. Problem Statement: I am trying to model and optimize a placement problem of placing the nodes of an undirected graph in a grid of cells such that the weighted Euclidean length is minimized subject to the constraint each grid cell can contain only a certain number of nodes based on its weighted-capacity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |