// SPDX-FileCopyrightText: 2020 Roberto Posenato // // SPDX-License-Identifier: LGPL-3.0-or-later package it.univr.di.labeledvalue; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import org.netbeans.validation.api.Problems; import org.netbeans.validation.api.Validator; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.Serial; import java.io.Serializable; import java.util.Arrays; import java.util.logging.Logger; /** * Represents an 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 label is consistent when it does not contain opposite literals. A label {@code L'} subsumes a label * {@code L} iff {@code L'} implies {@code L} ({@code ⊨ L' ⇒ L}). *
* In other words, if {@code L} is a sub-label of {@code 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 {@code int} for representing the state of literals composing a label: the two {@code 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 it.univr.di.labeledvalue.Literal#ABSENT}, {@link it.univr.di.labeledvalue.Literal#STRAIGHT}, * {@link it.univr.di.labeledvalue.Literal#NEGATED}, {@link it.univr.di.labeledvalue.Literal#UNKNOWN}) of the literal * associated to the position. *
* Using only 32 possible propositions, it is possible to cache the two {@code 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 $Rev$ */ @SuppressWarnings("SubtractionInCompareTo") @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS", justification = "I prefer to return null for saying no answer is possible.") public final class Label implements Comparable