![]() It's great when you look for code, probably I do something stupid and.but there is line czest = (czest + 1) and it works well. Trying to repair checked about change the 'wyjscie' from array to list. Gives me error ValueError: setting an array element with a sequence. Wyjscie = np.around(probc * nobins)Īnd this line(yeah last :C) : H = wyjscie + 1] Smallest eigenvalue -7.I'm not sure what i did wrong with this code: import cv2Ĭzest = (czest + 1) 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) The vast majority of users will need only create constraints of the first three types. # Variable to store sum of node weights in a grid cell CVXPY has seven types of constraints: non-positive, equality or zero, positive semidefinite, second-order cone, exponential cone, 3-dimensional power cones, and N-dimensional power cones. 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 Yes, there are such functions ( geomean ), but their usage must conform to the ruleset of Disciplined Convex Programming. # subject to the constraint that number of nodes in a grid cell Although perhaps you mean a function which takes in a single array and returns a scalar (the product of all entries in that array). # 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. |