Skip to content

Commit

Permalink
Improved version for implicit tuplets
Browse files Browse the repository at this point in the history
  • Loading branch information
hbitteur committed Jan 31, 2025
1 parent 210809e commit 69a0abf
Show file tree
Hide file tree
Showing 14 changed files with 619 additions and 390 deletions.
20 changes: 14 additions & 6 deletions app/src/main/java/org/audiveris/omr/math/InjectionSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
// </editor-fold>
package org.audiveris.omr.math;

import org.audiveris.omr.util.WrappedInteger;

import java.util.Arrays;

/**
* Class <code>InjectionSolver</code> handles the injection of a collection of elements
* (called domain) into another collection of elements (called range, or co-domain).
* <p>
* It finds a mapping that minimizes the global mapping distance, given the individual distance for
* each domain/range elements pair. This implementation is based on a brute-force approach and thus
* should be used with small sizes only.
* each domain/range elements pair.
* <p>
* NOTA: This implementation is based on a brute-force approach and thus should be used with small
* sizes only.
*
* @author Hervé Bitteur
*/
Expand Down Expand Up @@ -109,9 +113,10 @@ private void dump ()
*
* @param id index of provided domain item
* @param cost current configuration cost
* @return the final cost
*/
private void inspect (final int id,
final int cost)
private int inspect (final int id,
final int cost)
{
// System.out.println("inspect id=" + id + " cost=" + cost);
for (int ir = 0; ir < rangeSize; ir++) {
Expand All @@ -135,6 +140,8 @@ private void inspect (final int id,
free[ir] = true;
}
}

return bestCost;
}

//-------//
Expand All @@ -143,13 +150,14 @@ private void inspect (final int id,
/**
* Report (one of) the mapping(s) for which the global distance is minimum.
*
* @param bestCost (output) the best cost found
* @return an array parallel to the domain collection, which for each (domain) element gives the
* mapped range element
*/
public int[] solve ()
public int[] solve (WrappedInteger bestCost)
{
Arrays.fill(free, true);
inspect(0, 0);
bestCost.value = inspect(0, 0);

return bestConfig;
}
Expand Down
25 changes: 15 additions & 10 deletions app/src/main/java/org/audiveris/omr/sheet/rhythm/ChordPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ public class ChordPair
{
//~ Instance fields ----------------------------------------------------------------------------

public final AbstractChordInter one;
public final AbstractChordInter rookie;

public final AbstractChordInter two;
public final AbstractChordInter active;

public Integer cost;

//~ Constructors -------------------------------------------------------------------------------

public ChordPair (AbstractChordInter one,
AbstractChordInter two)
public ChordPair (AbstractChordInter rookie,
AbstractChordInter active,
Integer cost)
{
this.one = one;
this.two = two;
this.rookie = rookie;
this.active = active;
this.cost = cost;
}

//~ Methods ------------------------------------------------------------------------------------
Expand All @@ -60,22 +64,23 @@ public boolean equals (Object obj)

final ChordPair that = (ChordPair) obj;

return (one == that.one) && (two == that.two);
return (rookie == that.rookie) && (active == that.active);
}

@Override
public int hashCode ()
{
int hash = 3;
hash = (79 * hash) + Objects.hashCode(this.one);
hash = (79 * hash) + Objects.hashCode(this.two);
hash = (79 * hash) + Objects.hashCode(this.rookie);
hash = (79 * hash) + Objects.hashCode(this.active);

return hash;
}

@Override
public String toString ()
{
return "ChordPair{ch#" + one.getId() + ",ch#" + two.getId() + "}";
return ((cost != null) ? cost : "") + (active != null ? "#" + active.getId() : " null")
+ "--#" + rookie.getId();
}
}
Loading

0 comments on commit 69a0abf

Please sign in to comment.