Skip to content

Commit

Permalink
Merge upstream and origin
Browse files Browse the repository at this point in the history
  • Loading branch information
ramongonze committed Jul 1, 2020
2 parents ab5bc68 + d4071a9 commit e65792f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
4 changes: 2 additions & 2 deletions data/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@
/ss13acs_hierarchy_o_SCHG.csv
/ss13acs_hierarchy_o_SCHL.csv
/ss13acs_hierarchy_o_SEX.csv
/highdimensional-small.csv
/highdimensional.csv
/highdimensional.csv
/highdimensional-small.csv
71 changes: 66 additions & 5 deletions src/main/org/deidentifier/arx/ARXLattice.java
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public static LatticeDeserializationContext getDeserializationContext() {
public Access access() {
return access;
}

/**
* Materializes any non-materialized predecessors and successors
*/
Expand Down Expand Up @@ -1055,7 +1055,7 @@ public int compare(ARXNode o1, ARXNode o2) {
node.access.setHighestScore(max);
}
}

/**
* Returns the bottom node.
*
Expand All @@ -1064,7 +1064,7 @@ public int compare(ARXNode o1, ARXNode o2) {
public ARXNode getBottom() {
return bottom;
}

/**
* Returns the highest score. Lower is better.
* @return
Expand All @@ -1076,7 +1076,7 @@ public InformationLoss<?> getHighestScore(){
}
return this.maximumInformationLoss;
}

/**
* Returns the levels of the generalization lattice.
*
Expand All @@ -1085,7 +1085,7 @@ public InformationLoss<?> getHighestScore(){
public ARXNode[][] getLevels() {
return levels;
}

/**
* Returns the lowest score. Lower is better.
* @return
Expand All @@ -1098,6 +1098,67 @@ public InformationLoss<?> getLowestScore(){
return this.minimumInformationLoss;
}

/**
* Returns the ARXNode for the given generalization scheme, <code>null</code> if not found.
* This method does have side effects, as it expands all nodes on the path from bottom to the
* node returned.
* @param transformation
* @return
*/
public ARXNode getNode(int[] transformation) {

// Prepare
ARXNode node = getBottom();

// Search
while (!Arrays.equals(node.getTransformation(), transformation)) {

// Successors
node.expand();
ARXNode[] successors = node.getSuccessors().clone();

// Not found
if (successors.length == 0) {
return null;
}

// Sort according to distance
Arrays.sort(successors, new Comparator<ARXNode>() {

@Override
public int compare(ARXNode o1, ARXNode o2) {
return Integer.compare(getDistance(o1.getTransformation(), transformation),
getDistance(o2.getTransformation(), transformation));

}

/**
* Calculate distance
* @param current
* @param target
* @return
*/
private int getDistance(int[] current, int[] target) {
int distance = 0;
for (int i = 0; i < current.length; i++) {
if (current[i] > target[i]) {
return Integer.MAX_VALUE;
} else {
distance += target [i] - current[i];
}
}
return distance;
}
});

// Take closest node
node = successors[0];
}

// Done
return node;
}

/**
* Returns the number of nodes.
*
Expand Down

0 comments on commit e65792f

Please # to comment.