diff --git a/guessRhythm/main.py b/guessRhythm/main.py index ec57469..a7365cc 100644 --- a/guessRhythm/main.py +++ b/guessRhythm/main.py @@ -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() diff --git a/js/duration.js b/js/duration.js index 7a891fa..83798e2 100644 --- a/js/duration.js +++ b/js/duration.js @@ -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; diff --git a/js/rhythmguess.js b/js/rhythmguess.js index 77ee064..4413b23 100644 --- a/js/rhythmguess.js +++ b/js/rhythmguess.js @@ -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); } }); @@ -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;