11from flamapy .core .transformations import ModelToModel
2- from flamapy .metamodels .fm_metamodel .models import FeatureModel
3- from flamapy .metamodels .pysat_metamodel .transformations import FmToPysat
2+ from flamapy .metamodels .fm_metamodel .models import FeatureModel , ClauseSet
43from flamapy .metamodels .sharpsat_metamodel .models import SharpSATModel
54
65
76class FmToSharpSAT (ModelToModel ):
87 """Transform a feature model into a SharpSAT (CNF) model.
98
10- The CNF is produced by reusing the SAT metamodel's ``FmToPysat `` transformation , so
11- the same constraint encoding (and the optional Tseytin encoding via ``cnf_method``) is
12- available here.
9+ The CNF is produced by the feature-model ``ClauseSet `` (no SAT-solver dependency) , so the
10+ same constraint encoding (and the optional Tseytin encoding via ``cnf_method``) is available
11+ here.
1312 """
1413
1514 @staticmethod
@@ -26,16 +25,11 @@ def __init__(self, source_model: FeatureModel, cnf_method: str = 'distributive')
2625 self .destination_model = SharpSATModel ()
2726
2827 def transform (self ) -> SharpSATModel :
29- # Only pass cnf_method when a non-default encoding is requested, so the plugin also
30- # works against releases of flamapy-sat that predate the Tseytin cnf_method option.
31- if self .cnf_method == 'distributive' :
32- sat_model = FmToPysat (self .source_model ).transform ()
33- else :
34- sat_model = FmToPysat (self .source_model , cnf_method = self .cnf_method ).transform ()
28+ clause_set = ClauseSet .from_feature_model (self .source_model , cnf_method = self .cnf_method )
3529 model = self .destination_model
36- model .clauses = [list (clause ) for clause in sat_model . get_all_clauses () .clauses ]
37- model .variables = dict (sat_model .variables )
38- model .features = dict (sat_model .features )
39- model .auxiliary_variables = set (sat_model .auxiliary_variables )
30+ model .clauses = [list (clause ) for clause in clause_set .clauses ]
31+ model .variables = dict (clause_set .variables )
32+ model .features = dict (clause_set .features )
33+ model .auxiliary_variables = set (clause_set .auxiliary_variables )
4034 model .original_model = self .source_model
4135 return model
0 commit comments