EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.kernel.bo.logic.model]

COVERAGE SUMMARY FOR SOURCE FILE [PredicateVariableInterpreter.java]

nameclass, %method, %block, %line, %
PredicateVariableInterpreter.java100% (1/1)83%  (5/6)68%  (113/166)72%  (29/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PredicateVariableInterpreter100% (1/1)83%  (5/6)68%  (113/166)72%  (29/40)
toString (): String 0%   (0/1)0%   (0/53)0%   (0/11)
PredicateVariableInterpreter (Model): void 100% (1/1)100% (16/16)100% (5/5)
clear (): void 100% (1/1)100% (7/7)100% (3/3)
getPredicate (PredicateVariable): Predicate 100% (1/1)100% (9/9)100% (1/1)
getPredicateVariableSelection (PredicateVariable): int 100% (1/1)100% (34/34)100% (8/8)
next (): boolean 100% (1/1)100% (47/47)100% (12/12)

1/* This file is part of the project "Hilbert II" - http://www.qedeq.org
2 *
3 * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4 *
5 * "Hilbert II" is free software; you can redistribute
6 * it and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15 
16package org.qedeq.kernel.bo.logic.model;
17 
18import java.util.ArrayList;
19import java.util.List;
20 
21import org.qedeq.base.utility.Enumerator;
22 
23 
24/**
25 * This class calculates a new truth value for a given formula for a given interpretation.
26 *
27 * @author  Michael Meyling
28 */
29public final class PredicateVariableInterpreter {
30 
31    /** List of predicate variables. */
32    private List predicateVariables;
33 
34    /** List of counters for predicate variables. */
35    private List predicateVariableCounters;
36 
37    /** Model contains entities. */
38    private Model model;
39 
40    /**
41     * Constructor.
42     *
43     * @param   model   Model we work on.
44     */
45    public PredicateVariableInterpreter(final Model model) {
46        this.model = model;
47        predicateVariables = new ArrayList();
48        predicateVariableCounters = new ArrayList();
49    }
50 
51    private int getPredicateVariableSelection(final PredicateVariable var) {
52        int selection;
53        if (predicateVariables.contains(var)) {
54            final int index = predicateVariables.indexOf(var);
55            selection = ((Enumerator) predicateVariableCounters.get(index)).getNumber();
56        } else {
57//            System.out.println("added predicate variable " + var);
58            selection = 0;
59            predicateVariables.add(var);
60            predicateVariableCounters.add(new Enumerator());
61        }
62        return selection;
63    }
64 
65    /**
66     * Get model predicate for predicate variable.
67     *
68     * @param   var     For this predicate variable.
69     * @return  Predicate for model.
70     */
71    public Predicate getPredicate(final PredicateVariable var) {
72        return model.getPredicate(var.getArgumentNumber(),
73            getPredicateVariableSelection(var));
74    }
75 
76    /**
77     * Change to next valuation.
78     *
79     * @return  Is there a next new valuation?
80     */
81    public boolean next() {
82        boolean next = true;
83        for (int i = predicateVariables.size() - 1; i >= -1; i--) {
84            if (i < 0) {
85                next = false;
86                break;
87            }
88            final PredicateVariable var = (PredicateVariable) predicateVariables.get(i);
89            final Enumerator number = (Enumerator) predicateVariableCounters.get(i);
90            if (number.getNumber() + 1 < model.getPredicateSize(var.getArgumentNumber())) {
91                number.increaseNumber();
92                break;
93            }
94            number.reset();
95        }
96        return next;
97    }
98 
99    public String toString() {
100        final StringBuffer buffer = new StringBuffer();
101        buffer.append("predicate variables {");
102        for (int i = 0; i < predicateVariables.size(); i++) {
103            if (i > 0) {
104                buffer.append(", ");
105            }
106            PredicateVariable var = (PredicateVariable) predicateVariables.get(i);
107            buffer.append(predicateVariables.get(i));
108            buffer.append("=");
109            buffer.append(getPredicate(var));
110        }
111        buffer.append("}");
112        return buffer.toString();
113    }
114 
115    /**
116     * Clear variable interpretation.
117     */
118    public void clear() {
119        predicateVariables.clear();
120        predicateVariableCounters.clear();
121    }
122 
123 
124}

[all classes][org.qedeq.kernel.bo.logic.model]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov