필터 지우기
필터 지우기

P-Median Example Question

조회 수: 4 (최근 30일)
Danielle Strong
Danielle Strong 2016년 4월 20일
댓글: Arnab Sen 2016년 4월 27일
Hello, I am trying to code a simple p-median problem. This is what I have so far:
%define data
D = D1; %(896,896) distance matrix
p = 10;
%define variables
x = var(896,896);
y = var(896,1);
%define constraints
F = [sum(y)== p, x <= repmat(y',896,1), sum(x)==1];
%define obj
obj= sum(sum(D.*x));
%solve;default is minimize
solvesdp(F,obj)
But I am getting this error:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Any suggestions would be appreciated. Thank you.
  댓글 수: 2
Danielle Strong
Danielle Strong 2016년 4월 20일
Also, the x and y are supposed to be binary. Not sure how to do that.
Arnab Sen
Arnab Sen 2016년 4월 27일
x and y are 0 in the script

댓글을 달려면 로그인하십시오.

답변 (1개)

Arnab Sen
Arnab Sen 2016년 4월 27일
Hello Danielle,
I observe the error is coming because of the following statement:
F = [sum(y)== p, x <= repmat(y',896,1), sum(x)==1];
Here sum(y)== p and sum(x)==1 outputs 1X1 Boolean but x <= repmat(y',896,1) yields Boolean vector of 896X1. The three vector can not be concatenated horizontally due to this dimension mismatch. Modify the aforementioned statement to either one of the following depending on the rest of the code:
F = [sum(y)== p, x <= repmat(y',1,896), sum(x)==1];
or merge them vertically as below:
F = [sum(y)== p; x <= repmat(y',896,1); sum(x)==1];

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by