[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] comparing variable binary vector to each row of static m
From: |
glpk xypron |
Subject: |
Re: [Help-glpk] comparing variable binary vector to each row of static matrix |
Date: |
Tue, 07 Jun 2011 19:38:24 +0200 |
Hello Manuel,
see below.
Best regards
Xypron
# rows
set R := {0..3};
# columns
set C := {0..2};
# matrix
param p{R,C}, symbolic;
# column values
var x{C}, binary;
# row matches
var y{R}, <= 1;
# maximize number of matches
maximize obj:
sum{r in R} y[r];
# match 0s
s.t. c0{r in R, c in C: p[r,c] = 0} :
y[r] <= 1-x[c];
# match 1s
s.t. c1{r in R, c in C: p[r,c] = 1} :
y[r] <= x[c];
# solve
solve;
# output solution
printf "\nNumber of matches: %d\n", sum{r in R} y[r];
printf "Solution vector: ";
printf {c in C} "%d ", x[c];
printf "\n\n";
printf "matched rows:\n";
for {r in R: y[r] > .5} {
printf {c in C} "%1s ", p[r,c];
printf "\n";
}
printf "\n";
data;
param p :
0 1 2 :=
0 1 0 '*'
1 1 0 1
2 1 1 1
3 '*' 0 1;
end;
-------- Original-Nachricht --------
> Datum: Mon, 6 Jun 2011 23:55:06 -0700 (PDT)
> Betreff: Re: [Help-glpk] comparing variable binary vector to each row of
> static matrix
>
> hello xypron,
>
> thanks for your answer, unfortunately im stuggling with matching the
> individual cells. i adapted my attempt to your description, but i still
> have
> problems matching the individual cells. P are the columns, T are the rows.
> unfortunately using variables in if-constraints is not allowed (st
> matchcells), resulting in an error. the other way i could think of is
> using
> multiplication but it results in non linearity.
>
>
> set P := 1..4;
> set T := 1..9;
>
> param matrix{t in T, p in P}, integer, >= -1, <= 1;
>
> var vector{p in P}, binary;
> var cellmatch{t in T, p in P}, binary;
> var rowmatch{t in T}, binary;
>
> subject to matchcells{t in T, p in P}: cellmatch[t,p] = (if matrix[t,p] ==
> -1 || matrix[t,p] == vector[p] then 1 else 0);
> subject to matchrows{t in T}: rowmatch[t] = ((sum{p in P} cellmatch[t,p])
> /
> card(P));
>
> maximize z: sum{t in T} (rowmatch[t]);
>
>
> i guess i did not understand what you ment by "real variables for each
> row".
> i would be glad if you could give me further advice.
>
> thanks,
> manuel
>
>
> xypron wrote:
> >
> > Hello Manual,
> >
> > use binary variables for each column and real variables (>=0, <=1) for
> > each row, describing if the row is matched. Add constraints. Maximize
> the
> > number of row matches.
> >
> > Best regards
> >
> > Xypron
> >
>
> --
> View this message in context:
> http://old.nabble.com/comparing-variable-binary-vector-to-each-row-of-static-matrix-tp31787965p31789483.html
> Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.
>
>
> _______________________________________________
> Help-glpk mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-glpk
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de