Class NetworkFingerprint
TemporalConstraintGraph.
The fingerprint is sha256:v1: followed by the lowercase hexadecimal encoding of the SHA-256 digest of the
canonical semantic form of the graph, defined in this class. The canonical form is a line-oriented UTF-8 text that
depends only on the semantic content of the network, never on the GraphML file that produced it, on the order in
which nodes and edges were inserted, nor on the concrete backend (SparseTCGraph or DenseTCGraph).
Canonical form. Records are separated by '\n', fields within a record by '\t':
type=<TemporalConstraintNetworkType> node<\t><name>[<\t><observed>][<\t><parameter>][<\t><label>][<\t><potential>][<\t><lognormal>] edge<\t><source><\t><destination><\t><name><\t><constraintType>[<\t><labeledValues>][<\t><value>][<\t><case>][<\t><upper>][<\t><lower>]Node records appear in name order; edge records appear ordered by (source name, destination name). The name of an edge is not part of the form: the pair of endpoints identifies it, since the model admits no parallel edges, and renaming an edge does not change the network.
The optional fields are present only for the network kinds that TCGraphMLWriter writes and
TCGraphMLReader reads back (writer/reader parity), and mirror exactly the accessors those classes use:
| field | kinds that persist it |
|---|---|
| observed | OSTNU, CSTN, CSTNU, CSTNPSU, PCSTNU |
| parameter | PCSTNU always; CSTNU, CSTNPSU when at least one node is a parameter node |
| label | CSTN, CSTNU, CSTNPSU, PCSTNU |
| potential | OSTNU, CSTN, CSTNU, CSTNPSU, PCSTNU (the empty-A-Label view) |
| lognormal | PSTN (empty when the node has no distribution) |
| labeledValues | OSTNU, CSTN, CSTNU, CSTNPSU, PCSTNU |
| value | STN, STNU, PSTN |
| case | STNU, PSTN (empty when the edge has no case label) |
| upper, lower | OSTNU, CSTNU, CSTNPSU, PCSTNU |
observedis the observed-proposition character (Constants.UNKNOWNwhen the node observes nothing);parameteris1or0;labelisLabel.toString();potentialis the(label:value)pairs,';'-joined, ordered by (label, value);lognormalislocation;scale;shift(locale-independent);valueis the ordinary edge weight as an integer;caseisUC(name):valueorLC(name):value;upperandlowerare the(aLabel:label:value)triples,';'-joined, ordered by (aLabel, label, value);aLabelis the canonical form of an A-Label: the names of its A-Letters, sorted lexicographically and','-joined (the empty string for the empty A-Label). Names, notALabel.toString(), are used because the latter is ordered by alphabet-registration position and would make the fingerprint depend on insertion order;- names and labels are escaped by replacing
'\'with"\\",'\t'with"\t"and'\n'with"\n".
The canonical form deliberately omits presentation and derived data: coordinates, graph name, annotations (including
stored check outcomes), edge routes, node isContingent flags (derived from edge weights), the Z
designation (derived from the node name) and the A-Label-keyed node potentials (never persisted). As a consequence
the fingerprint of a network is stable across a save/read round trip — with one documented exception: a graph that
declares itself CSTNU but contains parameter nodes is written and reloaded as PCSTNU (see TCGraphMLReader),
so its type field, hence its fingerprint, changes on reload.
- Author:
- posenato
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription(package private) static StringcanonicalForm(TemporalConstraintGraph<? extends Edge> graph) Returns the canonical semantic form ofgraph, as defined in the class documentation.static booleanisVersionComparable(String storedFingerprint) Tells whetherstoredFingerprintcarries the current version prefix, i.e. whether it was produced by a release with the same canonical form and hashing scheme as this one.static booleanmatches(String storedFingerprint, TemporalConstraintGraph<? extends Edge> graph) ReturnstrueiffstoredFingerprintis version-comparable and equals the fingerprint of the semantic content ofgraph.static Stringof(TemporalConstraintGraph<? extends Edge> graph) Returns the fingerprint of the semantic content ofgraph.
-
Field Details
-
VERSION
Version tag of the fingerprint format. When the canonical form or the hashing scheme changes, this tag must change too, so that fingerprints computed by an older release are no longer mistaken for current ones.- See Also:
-
PREFIX
Every fingerprint starts with this prefix.isVersionComparable(String)recognizes it.- See Also:
-
-
Method Details
-
of
Returns the fingerprint of the semantic content ofgraph.- Parameters:
graph- a temporal constraint graph- Returns:
PREFIX+ lowercase hex SHA-256 of the canonical semantic form ofgraph
-
canonicalForm
Returns the canonical semantic form ofgraph, as defined in the class documentation.- Parameters:
graph- a temporal constraint graph- Returns:
- the canonical form of
graph
-
isVersionComparable
Tells whetherstoredFingerprintcarries the current version prefix, i.e. whether it was produced by a release with the same canonical form and hashing scheme as this one. A fingerprint whose version differs is not a mismatch of the network content: it cannot be compared at all.- Parameters:
storedFingerprint- the fingerprint stored alongside a check outcome, possiblynull- Returns:
trueiffstoredFingerprintstarts withPREFIX
-
matches
public static boolean matches(@Nullable String storedFingerprint, @Nonnull TemporalConstraintGraph<? extends Edge> graph) ReturnstrueiffstoredFingerprintis version-comparable and equals the fingerprint of the semantic content ofgraph. A stored fingerprint with a different version is reported asfalsehere; useisVersionComparable(String)to tell "not comparable" apart from a genuine content mismatch.- Parameters:
storedFingerprint- the fingerprint stored alongside a check outcome, possiblynullgraph- the graph to compare against- Returns:
trueiffstoredFingerprintis comparable and equalsof(TemporalConstraintGraph)
-