Hi there,
I'm working on a design with a counter constraint (similar in a way to partial profile). there are many attributes but one set of 7 has the following constraint. I can allow 0, 1, 2, or 3 of the 7 binary attributes to be 1.
A snippit of code.
U(A) = ... +
b1.d[0]*att1[0,1] +
b2.d[0]*att2[0,1] +
...
b7.d[0]*att7[0,1] +
... (more attributes)
etc.
I have in mind:
;cond:
if (a1.att1 = 1 and a1.att2 = 1 and a1.att3 = 1, a1.att4 = 0),
if (a1.att1 = 1 and a1.att2 = 1 and a1.att3 = 1, a1.att5 = 0),
for many lines.
Is there a simpler way to count the number of 1s and set a cap at 3? How do I do that?
Thanks for your help.
Compound contraint
Moderators: Andrew Collins, Michiel Bliemer, johnr
-
- Posts: 2056
- Joined: Tue Mar 31, 2009 4:13 pm
Re: Compound contraint
I think there is an easier way, namely:
;require:
a1.att1 + a1.att2 + a1.att3 + a1.att4 + a1.att5 + ... <= 3
You also need to use another algorithm for this, namely:
;alg = mfederov(candidates = xxxx)
This algorithm lets go of attribute level balance, but this is typically not problematic, especially if you are using dummy or effects coding.
Michiel
;require:
a1.att1 + a1.att2 + a1.att3 + a1.att4 + a1.att5 + ... <= 3
You also need to use another algorithm for this, namely:
;alg = mfederov(candidates = xxxx)
This algorithm lets go of attribute level balance, but this is typically not problematic, especially if you are using dummy or effects coding.
Michiel
Re: Compound contraint
Thanks. I didn't realize it was that simple to use ;require. Fingers crossed the mfederov algorithm finds a useful design.