Expand description
Computing a difference model from two model states.
§Why this exists
IEC 61970-552 defines dm:DifferenceModel as the incremental form of exchange: rather
than resending a whole grid model, a producer sends the statements to retract and the
statements to assert. Reading, applying and writing one is
reader::read_difference,
Dataset::apply_difference and writer::write_difference.
This module supplies the piece those three imply and none of them provides:
producing a change set from a before and an after.
It is the operation an EMS performs every time it publishes an update, and it is decidable from what the crate already holds — objects keyed by mRID, values sorted by attribute, profile provenance per value — so it costs a walk of the two models and no new machinery.
use cim_kit::prelude::*;
use cim_kit::cgmes3::SCHEMA;
use cim_kit::diff::DiffOptions;
let base = Dataset::load(SCHEMA, ["base_EQ.xml", "base_SSH.xml"])?;
let updated = Dataset::load(SCHEMA, ["updated_EQ.xml", "updated_SSH.xml"])?;
let change = base.difference_to(&updated, &DiffOptions::default());
let out = std::fs::File::create("change_DIFF.xml")?;
cim_kit::writer::write_difference(SCHEMA, &change.model, out, &Default::default())?;§What the result guarantees
Applying the result to the base reproduces the target:
base.apply_difference(&base.difference_to(&target, o).model) leaves base holding
every value target holds, and none it does not. That round trip is a test, not a
claim — see tests/difference.rs.
§What a statement-level difference cannot say
Two limits are the standard’s, not this implementation’s, and both are reported rather than papered over:
- An object cannot be deleted, only emptied.
rdf:parseType="Statements"retracts statements; there is no statement that says “this identifier no longer denotes anything”. An object present in the base and absent from the target therefore becomes a subject with no properties.Dataset::prune_emptyremoves such shells where a consumer wants them gone. - A compound has no statement form.
Location.mainAddressholds aStreetAddressinline, and IEC 61970-552’s statement syntax has nowhere to put one. A changed compound is reported asRule::Structureand left out, because emitting it as text would fabricate a value.
Structs§
- Diff
Options - Options controlling how a difference is computed.
- Diff
Report - A computed change set, together with what could not be expressed.