Class STNUAddSemiRigidCycles
java.lang.Object
it.univr.di.cstnu.util.STNUAddSemiRigidCycles
Loads STNU instances previously generated by
STNURandomGenerator using the
add4or6NestedDiamond method (a chain of nested diamonds V(i) -> C(i) <= A(i) -> W, closed by
a single Uxxx node) and adds, to each diamond of the chain, the one edge that is missing to turn its
wait into a semi-rigid cycle: an ordinary path from A(i) back to V(i) whose length equals the
magnitude of the wait generated by that diamond, so that the wait and the path form a tight cycle.
The generator already provides every other constraint the tight path needs (the nesting edges
A(i+1) -> V(i) = -2 and, for the last diamond, Uxxx -> V(xxx) = -1); this class only supplies
the complementary edge A(i) -> A(i+1) (or A(xxx) -> Uxxx for the last diamond) with the exact
value that makes the path tight. A successfully processed instance also carries a DYNAMIC_CONTROLLABILITY
CheckOutcome, recorded once the repaired graph has been confirmed controllable (see
makeDynamicallyControllable(DenseTCGraph, Set)). Processing an instance means:
- Precondition: every node matching
W\d+must already have an outgoing non-derivededge (the invariantSTNURandomGeneratorestablishes since r1144). If someWis still a sink, the diamond it belongs to would constrain nothing, and the file is skipped. - Structure discovery: the unique
Uxxxnode is located, then the chain is walked backwards fromxxx-1requiring, at each step, the nodesA(i),V(i)and the nesting edgeA(i+1) -> V(i); the walk stops at the first missing element, and the last index reached is the first (outermost) diamond. No fixed depth (4 or 6) is assumed. - Value computation: for every diamond
iof the discovered chain, the tight-path lengthneed(i) = y(i) - vc(i)is computed from the graph itself, wherevc(i)is the value ofV(i) -> C(i)andy(i)is the upper bound of the contingent link(A(i), x, y, C(i))(read from either the not-yet-initialized or theSTNU.initAndCheck()-initialized representation). The added edge then gets valueneed(i)minus the already-present negative edge that closes the rest of the path. - Repair: if adding these edges makes the instance not dynamically controllable, every negative
requirement edge is relaxed by 1 and the check is repeated, except the specific edges the tight paths are
made of: the nesting edges
A(i+1) -> V(i), the edgeUxxx -> V(xxx), and the edges this class just added. Protection is by edge, not by node, so unrelated negative edges that happen to touch aUxxxorA(i)node (both can carry ordinary random constraints from the surrounding network) remain relaxable. - Verification: before saving, every tight path is re-measured on the repaired graph and compared
against
need(i); a mismatch aborts the save.
_withSRCycles. The suffix is inserted right
before the input file's trailing instance index (the zero-padded _NNN counter
STNURandomGenerator writes with %03d), if there is one, so the index stays the last thing
before the extension (e.g. ..._withOne4NestedDiamond_027.stnu becomes
..._withOne4NestedDiamond_withSRCycles_027.stnu); otherwise the suffix is simply appended to the stem,
as before. See computeOutputFileName(String, String).- Version:
- $Rev: 1 $
- Author:
- posenato
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA single tightening edge added to close one diamond's semi-rigid cycle.static final recordA run that must not be saved.static interfaceOutcome ofaddSemiRigidCycles(DenseTCGraph).static final recordA successful run: the graph passed in has been mutated in place (edges added, and possibly some negative requirement edges relaxed to restore dynamic controllability) and every tight path has been verified. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringEdge name prefix, consistent withSTNURandomGenerator.EDGE_NAME_PREFIX.(package private) static final StringSuffix inserted into the output filename before the extension.(package private) static final Loggerloggerstatic final StringVersion of the class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSemiRigidCycles(DenseTCGraph<STNUEdge> graph) Graph-level entry point.(package private) static StringcomputeOutputFileName(String originalName, String suffix) Computes the output file name fororiginalName:suffixis inserted immediately before the name's trailing instance index (seeinsertSuffixBeforeTrailingIndex(String, String)), keeping the original extension last.static voidEntry point.
-
Field Details
-
VERSIONandDATE
-
LOG
logger -
EDGE_NAME_PREFIX
Edge name prefix, consistent withSTNURandomGenerator.EDGE_NAME_PREFIX.- See Also:
-
FILE_NAME_SUFFIX
Suffix inserted into the output filename before the extension.- See Also:
-
-
Constructor Details
-
STNUAddSemiRigidCycles
public STNUAddSemiRigidCycles()
-
-
Method Details
-
main
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException, WellDefinitionException Entry point.- Parameters:
args- command-line arguments (one or more STNU file paths)- Throws:
IOException- if a file cannot be read or writtenParserConfigurationException- if the XML parser cannot be configuredSAXException- if a file does not contain valid GraphMLWellDefinitionException- if an STNU instance is not well-defined
-
addSemiRigidCycles
public static STNUAddSemiRigidCycles.Result addSemiRigidCycles(DenseTCGraph<STNUEdge> graph) throws WellDefinitionException Graph-level entry point. Given a graph produced bySTNURandomGenerator#add4or6NestedDiamond, adds one tightening edge per diamond of the discovered chain, repairs dynamic controllability if needed, and verifies that every tight path still measures what it should. The graph is mutated in place: edges are added, and, if a repair is needed, some existing negative requirement edges may be relaxed by 1 one or more times. Callers must not save the graph when aSTNUAddSemiRigidCycles.Failureis returned.- Parameters:
graph- the graph to process- Returns:
- a
STNUAddSemiRigidCycles.Successdescribing what was added, or aSTNUAddSemiRigidCycles.Failurewith the reason to skip - Throws:
WellDefinitionException- if a dynamic-controllability check performed while repairing the graph finds it not well-defined
-
computeOutputFileName
Computes the output file name fororiginalName:suffixis inserted immediately before the name's trailing instance index (seeinsertSuffixBeforeTrailingIndex(String, String)), keeping the original extension last. Package-visible so the naming rule can be tested directly.- Parameters:
originalName- the input file's name, extension includedsuffix- the suffix identifying this tool's output (e.g.FILE_NAME_SUFFIX)- Returns:
- the output file name
-