Skip to content

Commit

Permalink
updated according to changes in trace-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
sandragreiner committed Jul 1, 2024
1 parent e03292d commit 733b8a8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.variantsync.boosting.datastructure.Feature;
import org.variantsync.boosting.datastructure.MainTree;
import org.variantsync.boosting.position.ProductPosition;
import org.variantsync.boosting.product.Product;
import org.variantsync.boosting.product.Variant;
import org.variantsync.functjonal.Result;
import org.variantsync.vevos.simulation.util.io.CaseSensitivePath;
import org.variantsync.vevos.simulation.variability.pc.Artefact;
Expand Down Expand Up @@ -79,7 +79,7 @@ public double[] compare(MainTree maintree, Map<String, GroundTruth> productPC, S
long evaluatedNodes = 0;
for (ASTNode node : maintree.getTree().getAstNodes()) {
for (ProductPosition productPosition : maintree.getProductPositions(node)) {
Product product = productPosition.product;
Variant product = productPosition.variant;
assert product != null;

Artefact result = productPC.get(product.getName()).variant();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.variantsync.boosting.eval.util.VEVOSUtilities;
import org.variantsync.boosting.eval.util.VariantGenerationResult;
import org.variantsync.boosting.parsing.ESupportedLanguages;
import org.variantsync.boosting.product.Product;
import org.variantsync.boosting.product.ProductPassport;
import org.variantsync.boosting.product.Variant;
import org.variantsync.boosting.product.VariantPassport;
import org.variantsync.vevos.simulation.feature.sampling.Sample;
import org.variantsync.vevos.simulation.variability.SPLCommit;
import org.variantsync.vevos.simulation.variability.pc.SourceCodeFile;
Expand Down Expand Up @@ -150,7 +150,7 @@ public double[] conductExperiment(VariantGenerationResult variantGenerationResul
variantGenerationResult.variantGroundTruthMap(),
variantGenerationResult.variantConfigFileMap());

List<Product> products = traceBoosting.getProducts();
List<Variant> products = traceBoosting.getVariants();

// provide proactive mappings according to current percentage amount in config
RandomMapping.distributeMappings(products, variantGenerationResult.variantGroundTruthMap(), percentage,
Expand Down Expand Up @@ -188,10 +188,10 @@ public double[] conductExperiment(VariantGenerationResult variantGenerationResul
public TraceBoosting initBoosting(Path variantsDirectory, Map<String, GroundTruth> gtMap,
Map<String, Path> configFileMap) {

List<ProductPassport> productPassports = new ArrayList<>();
List<VariantPassport> productPassports = new ArrayList<>();
for (Map.Entry<String, GroundTruth> gtEntry : gtMap.entrySet()) {
String variantName = gtEntry.getKey();
productPassports.add(new ProductPassport(variantName, variantsDirectory.resolve(variantName),
productPassports.add(new VariantPassport(variantName, variantsDirectory.resolve(variantName),
configFileMap.get(variantName)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/variantsync/boosting/eval/util/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.variantsync.boosting.TraceBoosting;
import org.variantsync.boosting.datastructure.ASTNode;
import org.variantsync.boosting.position.ProductPosition;
import org.variantsync.boosting.product.Product;
import org.variantsync.boosting.product.Variant;
import org.variantsync.vevos.simulation.io.Resources;
import org.variantsync.vevos.simulation.util.io.CaseSensitivePath;
import org.variantsync.vevos.simulation.variability.pc.Artefact;
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void mapNode(Artefact result, ASTNode node, ProductPosition produc
* are stored
* @return An Artefact object representing the extracted PC
*/
public static Artefact findPC(Product product, Path variantsDirectory) {
public static Artefact findPC(Variant product, Path variantsDirectory) {
Artefact artefact;
try {
artefact = Resources.Instance().load(Artefact.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.variantsync.boosting.datastructure.ASTNode;
import org.variantsync.boosting.position.ProductPosition;
import org.variantsync.boosting.product.Product;
import org.variantsync.boosting.product.Variant;
import org.variantsync.vevos.simulation.variability.pc.Artefact;

import java.nio.file.Path;
Expand Down Expand Up @@ -34,19 +34,19 @@ public class NormalDistributionMapping {
* for RQ3)
* @return The products with mapped nodes
*/
public static Product[] distributeMappings(Product[] preproducts, Path variantsDirectory,
public static Variant[] distributeMappings(Variant[] preproducts, Path variantsDirectory,
Map<String, Artefact> product_pc, double percentage, double standardDeviation) {
// Calculate the total number of nodes in all preproducts
int numberOfAllNodes = 0;
for (Product product : preproducts) {
for (Variant product : preproducts) {
numberOfAllNodes += product.getProductAst().getAstNodes().size();
}

// Generate distribution array based on the percentage and standard deviation
int[] distribution = getDistribution(numberOfAllNodes, percentage, standardDeviation);

int j = 0;
for (Product product : preproducts) {
for (Variant product : preproducts) {
// Load PCs for a certain product from VEVOS
Artefact result = Mapping.findPC(product, variantsDirectory);
// Store PCs in the product_pc map
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/org/variantsync/boosting/eval/util/RandomMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.variantsync.boosting.TraceBoosting;
import org.variantsync.boosting.datastructure.*;
import org.variantsync.boosting.product.Product;
import org.variantsync.boosting.product.Variant;
import org.logicng.formulas.Formula;
import org.logicng.io.parsers.ParserException;
import org.logicng.io.parsers.PropositionalParser;
Expand Down Expand Up @@ -32,9 +32,9 @@ public class RandomMapping {
* @param percentage the percentage of mapping to apply
* @param strip the strip value to use for distribution
*/
public static void distributeMappings(List<Product> preproducts, Map<String, GroundTruth> gtMap, int percentage,
public static void distributeMappings(List<Variant> preproducts, Map<String, GroundTruth> gtMap, int percentage,
int strip) {
for (Product product : preproducts) {
for (Variant product : preproducts) {
// loading PCs for a certain product, PC from VEVOS
Artefact groundTruth = gtMap.get(product.getName()).variant();
// get Distribution
Expand All @@ -57,7 +57,7 @@ public static void distributeMappings(List<Product> preproducts, Map<String, Gro
* variant, with each element containing a randomly generated value of 0
* or 1.
*/
private static Integer[] getDistribution(Product product) {
private static Integer[] getDistribution(Variant product) {
int nodesN = product.getProductAst().getAstNodes().size();
Integer[] dist = new Integer[nodesN];
Arrays.fill(dist, 0);
Expand All @@ -75,12 +75,13 @@ private static Integer[] getDistribution(Product product) {
* Applies a distribution of mappings to a given product based on a ground truth
* artefact.
*
* This method iterates through the ASTNodes of the Product, filters out nodes
* This method iterates through the ASTNodes of the given Product, filters nodes
* with line numbers less than 1, and retrieves the presence condition of each
* node from the ground truth. It then shuffles the candidate nodes to randomize
* them and assigns mappings to a specified percentage of the nodes. The
* mappings are populated with random values (0 or 1) based on the presence
* condition of each node.
* node from the ground truth.
* Then, it shuffles the candidate nodes (whose presence condition is not 'true')
* to randomize them and assigns mappings to a given percentage of the nodes.
* The mappings are populated with random binary values (0 or 1) based on the
* presence condition of each node.
*
* @param product The Product object to apply the distribution to
* @param groundTruth The Artefact object representing the ground truth
Expand All @@ -90,7 +91,7 @@ private static Integer[] getDistribution(Product product) {
* 0 to 100
* @throws NullPointerException if either product or groundTruth is null
*/
private static void applyDistribution(Product product, Artefact groundTruth, int percentage, int strip) {
private static void applyDistribution(Variant product, Artefact groundTruth, int percentage, int strip) {
// Nodes that can be mapped
List<ASTNode> candidateNodes = new ArrayList<>();
Map<ASTNode, Node> pcMap = new HashMap<>();
Expand All @@ -114,7 +115,7 @@ private static void applyDistribution(Product product, Artefact groundTruth, int
}
}

// shuffle the target nodes to randomize
// shuffle the candidate nodes to randomly assign mappings
Collections.shuffle(candidateNodes);

int numberOfMappedNodes = (percentage * candidateNodes.size()) / 100;
Expand All @@ -123,7 +124,9 @@ private static void applyDistribution(Product product, Artefact groundTruth, int
+ candidateNodes.size()
+ " variable nodes (" + percentage + "%)");

// Populate the nodes with random values (0 or 1)
// Assign a mapping to the first number of nodes in the randomly shuffled set
// according to the determined percentage.
// The mapping simulates the proactive knowledge
int brokenFormulas = 0;
for (int i = 0; i < numberOfMappedNodes; i++) {
var node = candidateNodes.get(i);
Expand Down

0 comments on commit 733b8a8

Please sign in to comment.