Can i convert a binary matrix to a function?

Hello everyone!
i have a binary matrix R(m*n), each row has multiple "1" , i want to optimize it in order to get only "1" in each row and no more than 3 "1" in each column. i want to user an optmizer but all of them need an optmization function. so can i return the matrix to a function in order to solve this problem?
thanks in advance

6 Kommentare

Torsten
Torsten am 27 Sep. 2022
Bearbeitet: Torsten am 27 Sep. 2022
Something unsatisfactory with the code I provided ?
You need an objective function, but you can define f to be anything you like in the code (e.g. f=ones(n*m,1) or f=zeros(n*m,1)). The task of the optimizer is to return a feasible matrix - the objective value does not matter.
Maria
Maria am 27 Sep. 2022
@Torsten the optimizer always find the optimal solution right?
Torsten
Torsten am 27 Sep. 2022
If your matrix is such that your problem is solvable, it should find one such solution.
Of course, there are input matrices for which a solution does not exist.
You can see this from the error code.
And there is not "the optimal solution", but one of many others in general.
Maria
Maria am 28 Sep. 2022
@Torsten in the code you provided, i found a problem when i change the bound constraint of each column.
That's why i'm looking if there is another solution.
Torsten
Torsten am 28 Sep. 2022
Bearbeitet: Torsten am 28 Sep. 2022
What kind of problem ?
As I said, there are of course matrices for which no solution exists. And the smaller you choose the possible number of ones per column, the greater the probability.
But if the solver says that a feasible solution can not be found, you can trust that your matrix doesn't permit a solution.
Maria
Maria am 7 Okt. 2022
@Torsten okay! i got it , thank you very much for you help.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 27 Sep. 2022

0 Stimmen

Yes, you can return a matrix from the function. However, that would be considered multiple objectives, and you would need to use one of the multi-objective optimizers.
To use optimizers such as fmincon() or ga() your objective function needs to return a scalar (well, except as determined by any UseVectorized option that might be in effect.)
... which I already told you in your earlier question.

Gefragt:

am 27 Sep. 2022

Kommentiert:

am 7 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by