I get the following error: ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 1 and the array at index 1 has size 2 Prob = cvx.Problem(cvx.Minimize(cvx.trace(D - Y)), constraints) Question 2: This is how I wrote my python code: import numpy as npĭ = g.dot(one.transpose()) one.dot(g.transpose()) - 2.0 * G The code I used is also laid put for anyone who wants to try. Note: The part below has already been solved. Question 1: Is this SDP formulation correct? I am getting $\infty$ as the solution. I am a bit unsure if the second constraint is needed though. Problem: Given $n$ points in $d$-dimensional space, i.e. Smallest eigenvalue -7.I want to use the CVXPY Python toolbox to solve the simple classical multi-dimensional scaling problem. 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. |