Skip to content

Commit

Permalink
space counting
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Schwarzentruber committed Feb 12, 2024
1 parent 7464f4d commit 52e137b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
21 changes: 12 additions & 9 deletions guessRhythm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ def addDi(ct, i, coeff):

for i in range(n):
for j in range(n):
if i != j and dhat[i] >= dhat[j]:
errorVar = solver.NumVar(0, inf, "error when di is smaller than dj")
ct = solver.Constraint(0, inf, "di is generally greater than dj")
addDi(ct, i, 1)
addDi(ct, j, -1)
#ct is the constraint di - dj + err >= 0
ct.SetCoefficient(errorVar, 1)
objective.SetCoefficient(errorVar, 1)
if dhat[i] >= dhat[j]:
errorVar = solver.NumVar(0, inf, "error when di is smaller than dj")
ct = solver.Constraint(0, inf, "di is generally greater than dj")
ct.SetCoefficient(errorVar, 1)
addDi(ct, i, 1)
addDi(ct, j, -1)
#ct is the constraint di - dj + err >= 0
#ct is the constraint err >= dj - di
objective.SetCoefficient(errorVar, 1)



#makes that unprobable durations are more and more costly
for i in range(n):
for j in range(len(arrayOfDurations[i])):
objective.SetCoefficient(booleanVars[i][j], j)
objective.SetCoefficient(booleanVars[i][j], 0) #j

print(f"Solving with {solver.SolverVersion()}")
solver.Solve()
Expand Down
2 changes: 0 additions & 2 deletions js/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ function durationFractionToStr(d) {

for (let n of [1, 3, 7]) {
for (let i = 0; i < 6; i++) {


const possibleDuration = n / (2 ** i);
if (d == possibleDuration) {
const num = n;
Expand Down
4 changes: 2 additions & 2 deletions js/rhythmguess.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RhythmGuess {
try { element = new Element(token); } catch (e) { isElement = false; };
elements.push(element);
if (isElement) nbSpaces++;
nbSpacesArray.push(isElement ? 1 + (token.indexOf(".") >= 0) ? 0.5 : 0 : 0);
nbSpacesArray.push(isElement ? (1 + ((token.indexOf(".") >= 0) ? 0.5 : 0)) : 0);
}
});

Expand Down Expand Up @@ -211,7 +211,7 @@ class RhythmGuess {
const durationsSolution = await solve(elements.map((e) => e.dhat), possibleDurations, signatureValue);
setDurations(elements, durationsSolution);
const abcdResult = elementsToABCD(elements, durationsSolution);
console.log(abcdResult)
console.log("result of the inference: ", durationsSolution, abcdResult)
storeMemo(abcdStr, signature, abcdResult);
return abcdResult;

Expand Down

0 comments on commit 52e137b

Please sign in to comment.