package it.univr.di.labeledvalue; import java.util.Arrays; import java.util.logging.Logger; import org.jetbrains.annotations.Nullable; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; /** * Represents a immutable propositional label in the CSTN/CSTNU framework.
* A label is a (logic) conjunction of zero or more literals ({@link it.univr.di.labeledvalue.Literal}).
* A label without literals is called empty label and it is represented graphically as {@link it.univr.di.labeledvalue.Constants#EMPTY_LABEL}.
* A labels is consistent when it does not contains opposite literals. * A label L' subsumes a label L iff L' implies L (⊨ L' ⇒ L).
* In other words, if L is a sub-label of L'. *

* Design assumptions * Since in CSTN(U) project the memory footprint of a label is an important aspect, after some experiments, I have found that the best way * to represent a label is to limit the possible propositions to the range [a-z,A-F] and to use two int for representing the state of literals * composing a label: * the two int are used in pair; each position of them is associated to a possible literal (position 0 to 'a',...,position 32 to 'F'); given a * position, * the two corresponding bits in the two long can represent all possible four states ({@link Literal#ABSENT}, * {@link Literal#STRAIGHT}, {@link Literal#NEGATED}, {@link Literal#UNKNONW}) of the literal associated to the position.
* Using only 32 possible propositions, it is possible to cache the two int of a label as a long and, therefore, to cache the label for reusing it. *

*

* The following table represent execution times of some Label operations determined using different implementation of this class. *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Execution time for some operations w.r.t the core data structure of the class.
MethodTreeSetObjectAVLTreeSetObjectRBTreeSetbyte arraytwo inttwo longtwo int Immutable
Simple conjunction of '¬abcd' with '¬adefjs'='¬abcdefjs' (ms)0.0769610.0661160.0687980.0013090.0002990.0003170.000529
Execution time for an extended conjunction of '¬abcd' with * 'a¬c¬defjs'='¿ab¿c¿defjs' (ms)0.075830.0240990.0146270.0008430.0002030.0002350.000229
Execution time for checking if two (inconsistent) labels are consistent. * Details '¬abcd' with 'a¬c¬defjs' (ms)0.0040160.0016660.001660.001210.000750.000400.000122
Execution time for checking if two (consistent) labels are consistent. * Details '¬abcd' with '¬abcd' (ms)0.019460.0044570.0040990.0003920.0005580.0002250.000089
Execution time for checking if a literal is present in a label (the * literal is the last inserted) (ms)5.48E-44.96E-45.01E-42.69E-45.03E-47.47E-44.46E-4
Execution time for checking if a literal is present in a label (the * literal is not present) (ms)6.48E-47.71E-45.96E-41.84E-43.07E-42.33E-42.14E-4
Execution time for get the literal in the label with the same proposition * letter (the literal is present) (ms)0.0032721.83E-41.09E-41.27E-41.60E-41.32E-47.43E-5
Execution time for get the literal in the label with the same proposition * letter (the literal is not present) (ms)0.0025691.68E-41.0E-41.04E-41.60E-41.30E-45.25E-5
* All code for performance tests is in LabelTest class . * * @author Roberto Posenato * @version $Id: $Id */ public class Label implements Comparable