Closed LouisCG closed 8 years ago
I'm testing this, but getting lots of unexpected results. I'm trying to work out why.
I may as well debug the constraint factory functions that are there before this is merged.
For the constraints that are there, the two ints should be sufficient. Other values may be required for further constraints. Craig, I'll catch up with you another time with regards to how to grab info from the database when implementing the constraintsSatisfied function required for the algorithm.
I believe I found out what was wrong with the constraint functions. There was an off-by-one error when iterating over previous rounds and the getXTeamVs functions were incorrectly implemented in ConTable due to my lack of oversight regarding the MATCH_SET mask. It should be good now. Check out the changes for review when you can.
It works a lot better with the changes, but still fails some situations. It passes 16 different tests I've tried, but fails 3. Sorry if I'm using the function wrong.
it('4 teams, 3 round, 4 matches, home constraint (2) on first round (not satisified)', () => {
let factory = new ConstraintFactory()
let constraintMaxHome = factory.createMaxConsecHome(2)
let ct = new ConTable(4)
ct.setMatch(new Match(1, 0, 3))
ct.setMatch(new Match(1, 2, 1))
ct.setMatch(new Match(2, 1, 0))
ct.setMatch(new Match(2, 2, 3))
let result = constraintMaxHome(ct, new Match(0, 2, 0))
expect(result).toBe(false)
})
The result is true. It should be false because '2' would play 3 home games in a row.
it('4 teams, 3 round, 4 matches, home constraint (2) on second round (satisified)', () => {
let factory = new ConstraintFactory()
let constraintMaxHome = factory.createMaxConsecHome(2)
let ct = new ConTable(4)
ct.setMatch(new Match(0, 3, 0))
ct.setMatch(new Match(0, 2, 1))
ct.setMatch(new Match(2, 1, 3))
ct.setMatch(new Match(2, 0, 2))
let result = constraintMaxHome(ct, new Match(1, 0, 1))
expect(result).toBe(true)
})
The result is false. It should be true because team '0' would only play 2 games in a row.
it('6 teams, 5 round, 12 matches, home constraint (3) on first round (satisified)', () => {
let factory = new ConstraintFactory()
let constraintMaxHome = factory.createMaxConsecHome(3)
let ct = new ConTable(6)
ct.setMatch(new Match(1, 4, 3))
ct.setMatch(new Match(1, 2, 0))
ct.setMatch(new Match(1, 1, 5))
ct.setMatch(new Match(2, 2, 4))
ct.setMatch(new Match(2, 0, 1))
ct.setMatch(new Match(2, 5, 3))
ct.setMatch(new Match(3, 1, 4))
ct.setMatch(new Match(3, 0, 5))
ct.setMatch(new Match(3, 3, 2))
ct.setMatch(new Match(4, 2, 1))
ct.setMatch(new Match(4, 0, 3))
ct.setMatch(new Match(4, 5, 4))
let result = constraintMaxHome(ct, new Match(0, 2, 1))
expect(result).toBe(true)
})
The result is false. It should be true because team '2' would only play 3 games in a row (Max set to 3).
Nah, you're using the function correctly. I have a feeling I know what the problem is. I'll take another look today.
Right, I think I solved the problems there. Turns out I had structured a few of the loops completely incorrectly (including nesting for loops with the same iterator variable -- I wasn't paying attention, I guess).
Give them another run through your tests Craig. If there are still problems, send me all the tests for these functions as a code snippet over Slack and I'll work on them further while making sure regression doesn't complain.
Closes #85
Implemented the class for the Constraint Factory and shifted around the constraint enumeration. Other stuff may be moved to the constraint_factory.ts file as necessary.
Constraints are not implemented in teams yet. It's still using the naive TestTeamNoConstraint class from my demo. This will have to be replaced, probably by adding to the Team model so that constraint details can be stored and the interface that the fixture algorithm needs is implemented. This can be done as part of other issues in this epic (and after I have a chat with with you, Craig, so I don't accidentally wreck the database).