1+ import org .logicng .formulas .FormulaFactory ;
2+ import org .variantsync .boosting .TraceBoosting ;
3+ import org .variantsync .boosting .datastructure .ASTNode ;
4+ import org .variantsync .boosting .datastructure .Feature ;
5+ import org .variantsync .boosting .datastructure .MainTree ;
6+ import org .variantsync .boosting .parsing .ESupportedLanguages ;
7+ import org .variantsync .boosting .product .Variant ;
8+ import org .variantsync .boosting .product .VariantPassport ;
9+
10+ import java .nio .file .Path ;
11+ import java .util .*;
12+ import java .util .stream .Collectors ;
13+
14+ public class Demo {
15+
16+ public static void main (String [] args ) {
17+
18+ List <VariantPassport > variantPassports = createVariantPassports ();
19+
20+ TraceBoosting traceBoosting = new TraceBoosting (
21+ variantPassports ,
22+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/workdir" ),
23+ ESupportedLanguages .LINES );
24+
25+ // optionally the number of threads can be adjusted, per default it is set to the number of available system threads
26+ traceBoosting .setNumThreads (1 );
27+
28+ List <Variant > variants = traceBoosting .getVariants ();
29+ System .out .println ("initiated with " + variants .size () + " products" );
30+ applyDistribution (variants );
31+
32+ // runs the boosted comparison-based feature tracoing algorithm
33+ MainTree tree = traceBoosting .computeMappings ();
34+
35+ for (ASTNode n : tree .getTree ().getAstNodes ()) {
36+ if (!n .getMapping ().toString ().equals ("$true" )) {
37+ System .out .println (n .getMapping ()+ " mapped onto " + n .getCode ());
38+ }
39+ }
40+
41+ Set <String > relevantFeatures = variants .stream ().flatMap (p -> p .getFeatures ().stream ().map (Feature ::getName ))
42+ .collect (Collectors .toSet ());
43+
44+ System .out .println (relevantFeatures );
45+
46+ // for (Variant p : traceBoosting.getVariants())
47+ // {
48+ // System.out.println("Variant: " + p.getName());
49+ // for (ASTNode as : p.getAstNodesMainTree()) {
50+ // if (!as.getMapping().toString().equals("$true")) {
51+ // System.out.println( as.getMapping()+ " mapped onto " + as.getCode());
52+ // }
53+ // }
54+ // System.out.println();
55+ // }
56+ }
57+
58+ private static List <VariantPassport > createVariantPassports () {
59+ var variantPassports = new ArrayList <VariantPassport >(3 );
60+ variantPassports .add (
61+ new VariantPassport ("weighted" ,
62+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant1/src" ),
63+ //configFileMap.get(variantName)
64+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant1/config1.config" )
65+ )
66+ );
67+
68+ variantPassports .add (
69+ new VariantPassport ("directed" ,
70+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant2/src" ),
71+ //configFileMap.get(variantName)
72+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant2/config2.config" )
73+ )
74+ );
75+
76+ variantPassports .add (
77+ new VariantPassport ("colored" ,
78+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant3/src" ),
79+ Path .of (System .getProperty ("user.dir" ) + "/data/graph/variant3/config3.config" ))
80+ );
81+ return variantPassports ;
82+ }
83+
84+ // simulates setting manually annotations of some AST nodes
85+ private static void applyDistribution (List <Variant > variants ) {
86+ var factory = new FormulaFactory ();
87+ for (Variant p : variants ) {
88+ // Nodes that can be mapped
89+ if (p .getName ().equals ("weighted" )) {
90+ for (ASTNode n : p .getProductAst ().getAstNodes ()) {
91+ if (n .getCode ().contains ("List<Edge> edges();" ))
92+ n .setMapping (factory .variable ("E" ));
93+ }
94+ }
95+ if (p .getName ().equals ("weighted" )) {
96+ for (ASTNode n : p .getProductAst ().getAstNodes ()) {
97+ if (n .getCode ().contains ("public interface Graph {" ))
98+ n .setMapping (factory .variable ("G" ));
99+ }
100+ }
101+ if (p .getName ().equals ("directed" )) {
102+ for (ASTNode n : p .getProductAst ().getAstNodes ()) {
103+ if (n .getCode ().contains ("Graph subGraph(Color c);" ))
104+ n .setMapping (factory .variable ("C" ));
105+ }
106+ }
107+ if (p .getName ().equals ("colored" )) {
108+ for (ASTNode n : p .getProductAst ().getAstNodes ()) {
109+ if (n .getCode ().contains ("Graph subGraph(Color c);" ))
110+ n .setMapping (factory .variable ("C" ));
111+ }
112+ }
113+ }
114+ }
115+ }
0 commit comments