From 5d0ea3a3b3d7f2a49a732c435f56d7f5176b3ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Vi=E1=BA=BFt=20M=E1=BA=ABn?= Date: Thu, 8 Jun 2023 23:33:18 +0200 Subject: [PATCH] Improve the source code --- .../tugraz/ist/ase/hiconfit/KBStatistics.java | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/main/java/at/tugraz/ist/ase/hiconfit/KBStatistics.java b/src/main/java/at/tugraz/ist/ase/hiconfit/KBStatistics.java index 7ec5db7..ee6a084 100644 --- a/src/main/java/at/tugraz/ist/ase/hiconfit/KBStatistics.java +++ b/src/main/java/at/tugraz/ist/ase/hiconfit/KBStatistics.java @@ -31,7 +31,7 @@ import static com.google.common.base.Preconditions.checkArgument; /** - * The class that calculates the statistics of knowledge bases. + * The class calculates the statistics of given knowledge bases. * Supports the following knowledge bases: * - Feature Models from SPLOT, FeatureIDE, Glencoe, and other tools * - PC and Renault from https://www.itu.dk/research/cla/externals/clib/ @@ -120,15 +120,19 @@ public void calculate() throws IOException, FeatureModelParserException { if (options.getKb() != null) { for (String nameKb : options.getKb()) { KB kb = null; - if (nameKb.equals("PC")) { // if pc, then calculate the statistics of pc - System.out.println("\nCalculating statistics for PC..."); - kb = new PCKB(false); - } else if (nameKb.equals("Renault")) { // if Renault, then calculate the statistics of Renault - System.out.println("\nCalculating statistics for Renault..."); - kb = new RenaultKB(false); - } else if (nameKb.equals("Camera")) { // if Camera, then calculate the statistics of Camera - System.out.println("\nCalculating statistics for Camera..."); - kb = new CameraKB(false); + switch (nameKb) { + case "PC" -> { // if pc, then calculate the statistics of pc + System.out.println("\nCalculating statistics for PC..."); + kb = new PCKB(false); + } + case "Renault" -> { // if Renault, then calculate the statistics of Renault + System.out.println("\nCalculating statistics for Renault..."); + kb = new RenaultKB(false); + } + case "Camera" -> { // if Camera, then calculate the statistics of Camera + System.out.println("\nCalculating statistics for Camera..."); + kb = new CameraKB(false); + } } checkArgument(kb != null, "The knowledge base is not supported."); @@ -176,15 +180,14 @@ private void processFM(BufferedWriter writer, int counter, File file) throws IOE private void saveStatistics(BufferedWriter writer, int counter, KB kb) throws IOException { boolean consistent = kb.getModelKB().getSolver().solve(); - // TODO - use writer.newLine(); - writer.write(counter + "\n"); - writer.write("Name: " + kb.getName() + "\n"); - writer.write("Source: " + kb.getSource() + "\n"); - writer.write("#variables: " + kb.getNumVariables() + "\n"); - writer.write("#constraints: " + kb.getNumConstraints() + "\n"); - writer.write("#Choco variables: " + kb.getNumChocoVars() + "\n"); - writer.write("#Choco constraints: " + kb.getNumChocoConstraints() + "\n"); - writer.write("Consistency: " + consistent + "\n"); + writer.write(String.valueOf(counter)); writer.newLine(); + writer.write("Name: " + kb.getName()); writer.newLine(); + writer.write("Source: " + kb.getSource()); writer.newLine(); + writer.write("#variables: " + kb.getNumVariables()); writer.newLine(); + writer.write("#constraints: " + kb.getNumConstraints()); writer.newLine(); + writer.write("#Choco variables: " + kb.getNumChocoVars()); writer.newLine(); + writer.write("#Choco constraints: " + kb.getNumChocoConstraints()); writer.newLine(); + writer.write("Consistency: " + consistent); writer.newLine(); writer.flush(); } @@ -196,17 +199,17 @@ private void saveFMStatistics(BufferedWriter writer, int counter, KB kb, saveStatistics(writer, counter, kb); - writer.write("\n"); - writer.write("CTC ratio: " + ctc + "\n"); - writer.write("#features: " + fm.getNumOfFeatures() + "\n"); - writer.write("#relationships: " + fm.getNumOfRelationships() + "\n"); - writer.write("#constraints: " + fm.getNumOfConstraints() + "\n"); - writer.write("#MANDATORY: " + fm.getNumOfRelationships(MandatoryRelationship.class) + "\n"); - writer.write("#OPTIONAL: " + fm.getNumOfRelationships(OptionalRelationship.class) + "\n"); - writer.write("#ALTERNATIVE: " + fm.getNumOfRelationships(AlternativeRelationship.class) + "\n"); - writer.write("#OR: " + fm.getNumOfRelationships(OrRelationship.class) + "\n"); - writer.write("#REQUIRES: " + fm.getNumOfRequires() + "\n"); - writer.write("#EXCLUDES: " + fm.getNumOfExcludes() + "\n"); + writer.newLine(); + writer.write("CTC ratio: " + ctc); writer.newLine(); + writer.write("#features: " + fm.getNumOfFeatures()); writer.newLine(); + writer.write("#relationships: " + fm.getNumOfRelationships()); writer.newLine(); + writer.write("#constraints: " + fm.getNumOfConstraints()); writer.newLine(); + writer.write("#MANDATORY: " + fm.getNumOfRelationships(MandatoryRelationship.class)); writer.newLine(); + writer.write("#OPTIONAL: " + fm.getNumOfRelationships(OptionalRelationship.class)); writer.newLine(); + writer.write("#ALTERNATIVE: " + fm.getNumOfRelationships(AlternativeRelationship.class)); writer.newLine(); + writer.write("#OR: " + fm.getNumOfRelationships(OrRelationship.class)); writer.newLine(); + writer.write("#REQUIRES: " + fm.getNumOfRequires()); writer.newLine(); + writer.write("#EXCLUDES: " + fm.getNumOfExcludes()); writer.newLine(); writer.flush(); }