이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to write code for Assignment problem using GA matlab tool.
조회 수: 2 (최근 30일)
이전 댓글 표시
How to write code for Assignment problem using GA matlab tool.I'm not sure how to write code for xij=0 or 1.
Please clarify my doubt. Thanks in advance.
답변 (1개)
John D'Errico
2022년 6월 19일
Does GA allow you to specify that some variables are integer? (Yes.)
Does GA allow you to specify lower and upper bound limits on the variables? (Yes.)
Which integers lie in the closed interval [0,1]? (I'll let you answer that.)
댓글 수: 11
buvaneshwari tk
2022년 6월 19일
ObjectiveFunction = @myffapalpha0;
lb = [0 0]; % Lower bounds
ub = [100 100]; % Upper bounds
ConstraintFunction = @simple_constraintffap;
nvars = 16;
rng default % For reproducibility
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],lb,ub,ConstraintFunction)
buvaneshwari tk
2022년 6월 19일
where and how to write code for all the variables are in 1 (xij=0 or 1)?
Sam Chak
2022년 6월 19일
Not an expert in operations research, but I do hope the Example and MATLAB code in the following link help:
John D'Errico
2022년 6월 19일
편집: John D'Errico
2022년 6월 19일
First, you cannot simultaneously maximize AND minimize two different objectives, using an optimization tool.
You cannot simultaneuously optimize two separate things at once. Except that you can, but you need to use ideas from the field of multi-criteria optimization. In MATLAB, there is the tool fgoalattain, except that it cannot handle integer constraints.
Next, as pointed out by @Sam Chak, this is a linear problem, except that you cannot use a tool like intlinprog to solve that problem. (You would want intlinprog, because of the integer constraints. linprog has no ability to solve integer problems.)
Finally, since you have only 16 total variables, each of which can take on only two values, the simplest solution is to just evaluate the objectives for all possible sets of the parameters. That would look as if you have 65536=2^16 possible combinations. But as importantly, the constraints make it obvious that in fact, you don't have that many ways to do this. In fact, your constraints force this to be a problem where all of the matrices must be permutation matrices. There are only 24 possible 4x4 permutation matrices. We can find all 24 of them as permutations of the 4x4 identity matrix. So start with the 4x4 identity.
X = eye(4);
PermsList = perms(1:4)
PermsList = 24×4
4 3 2 1
4 3 1 2
4 2 3 1
4 2 1 3
4 1 3 2
4 1 2 3
3 4 2 1
3 4 1 2
3 2 4 1
3 2 1 4
As I said, 24 of them. We can find all admissable permutations as:
X = permute(reshape(X(PermsList,:),[24 4 4]),[2 3 1]);
For example, one such admissable permutation is:
X(:,:,5)
ans = 4×4
0 0 0 1
1 0 0 0
0 0 1 0
0 1 0 0
As you can see, each of them satisfy all of your constraints.
X
X =
X(:,:,1) =
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
X(:,:,2) =
0 0 0 1
0 0 1 0
1 0 0 0
0 1 0 0
X(:,:,3) =
0 0 0 1
0 1 0 0
0 0 1 0
1 0 0 0
X(:,:,4) =
0 0 0 1
0 1 0 0
1 0 0 0
0 0 1 0
X(:,:,5) =
0 0 0 1
1 0 0 0
0 0 1 0
0 1 0 0
X(:,:,6) =
0 0 0 1
1 0 0 0
0 1 0 0
0 0 1 0
X(:,:,7) =
0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
X(:,:,8) =
0 0 1 0
0 0 0 1
1 0 0 0
0 1 0 0
X(:,:,9) =
0 0 1 0
0 1 0 0
0 0 0 1
1 0 0 0
X(:,:,10) =
0 0 1 0
0 1 0 0
1 0 0 0
0 0 0 1
X(:,:,11) =
0 0 1 0
1 0 0 0
0 0 0 1
0 1 0 0
X(:,:,12) =
0 0 1 0
1 0 0 0
0 1 0 0
0 0 0 1
X(:,:,13) =
0 1 0 0
0 0 0 1
0 0 1 0
1 0 0 0
X(:,:,14) =
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 0
X(:,:,15) =
0 1 0 0
0 0 1 0
0 0 0 1
1 0 0 0
X(:,:,16) =
0 1 0 0
0 0 1 0
1 0 0 0
0 0 0 1
X(:,:,17) =
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
X(:,:,18) =
0 1 0 0
1 0 0 0
0 0 1 0
0 0 0 1
X(:,:,19) =
1 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
X(:,:,20) =
1 0 0 0
0 0 0 1
0 1 0 0
0 0 1 0
X(:,:,21) =
1 0 0 0
0 0 1 0
0 0 0 1
0 1 0 0
X(:,:,22) =
1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1
X(:,:,23) =
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
X(:,:,24) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Now you could merely loop through every possible plane of that array. Test them all, taking the one that makes you happy.
Regardless, you will still need to decide how to simultaneously choose between two disparate objectives, because the set that optimizes one will not be the set that optimizes the other. You will need to decide how to combine the two objectives into one.
Would you want to use GA to do this? Why in the name of god and little green apples would you do that, or even use intlinprog, when there are only 24 such possible matrices to consider?
buvaneshwari tk
2022년 6월 19일
ObjectiveFunction = @myffapalpha0;
lb = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; % Lower bounds
ub = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]; % Upper bounds
ConstraintFunction = @simple_constraintffap;
intcons = [];
options = [];
nvars = 16;
rng default % For reproducibility
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],lb,ub,ConstraintFunction,intcons,options)
buvaneshwari tk
2022년 6월 19일
For this code i get the values of varibles in between 0 and 1.
i want the value of variable in 0 or 1.
Torsten
2022년 6월 19일
For this code i get the values of varibles in between 0 and 1.
i want the value of variable in 0 or 1.
To achieve this, set
intcons = 1:16
And better use intlinprog instead of ga - it will be way faster.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)