Skip to content

Allow import of models with rational/double values in either mode - #311

Merged
davexparker merged 1 commit into
prismmodelchecker:masterfrom
davexparker:umb-exact
Oct 24, 2026
Merged

davexparker merged 1 commit into
prismmodelchecker:masterfrom
davexparker:umb-exact

Conversation

@davexparker

Copy link
Copy Markdown
Member

Importing a model whose values are stored as doubles in exact mode, or as rationals in non-exact mode, now works, with values converted as needed.

Previously:

  • a double-valued UMB file in exact mode failed with a ClassCastException;
  • a rational-valued UMB file in non-exact mode gave "Cannot import an exact model unless in exact mode";
  • a rational-valued text file (e.g. .tra) in non-exact mode gave "invalid value".

Conversions:

  • exact mode: doubles become rationals via their (shortest) decimal representation, e.g. 0.4 -> 2/5, matching how decimal values in text files are interpreted;
  • non-exact mode: rationals become the closest double, as for rational expressions in PRISM models.

For UMB files, the value type is now determined separately for each part (probabilities, exit rates, each reward structure). This also fixes a ClassCastException when importing, in non-exact mode, a file with double-valued probabilities but rational rewards.

Includes regression tests in prism-tests/functionality/import (dice.umb.exact.auto, third.umb.auto).

Fixes #309.

Importing a model whose values are stored as doubles in exact mode, or
as rationals in non-exact mode, now works, converting values as needed
(see issue prismmodelchecker#309). Previously, a double-valued UMB file in exact mode
failed with a ClassCastException, and a rational-valued UMB or text
(e.g. .tra) file in non-exact mode gave "Cannot import an exact model
unless in exact mode" or "invalid value", respectively.

In exact mode, doubles are converted to rationals via their (shortest)
decimal representation, e.g. 0.4 -> 2/5, matching how decimal values
in text files are interpreted. In non-exact mode, rationals are
converted to the closest double, as for rational expressions in PRISM
models.

For UMB files, the value type is determined separately for each part
(probabilities, exit rates, each reward structure), which also fixes a
ClassCastException when importing, in non-exact mode, a file with
double-valued probabilities but rational rewards.

Add regression tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Static review identified no blocking issues in the focused conversion changes and regression fixtures; tests were not executed.

No open issues 🎉

What changed in this PR

This PR addresses #309 by allowing explicit model imports to convert between rational and double values instead of rejecting mismatched modes or failing with a cast error.

Changes:

  • Decode UMB probabilities, exit rates, and rewards using each component’s stored type, converting to the requested evaluation mode.
  • Accept rational strings in floating-point parsing and remove model-wide exactness restrictions.
  • Add regression cases for exact, non-exact, mixed-type UMB, and rational text imports.
File Description
prism/​src/​symbolic/​build/​ExplicitFiles2MTBDD.java Removes the symbolic builder’s rejection of rational imports.
prism/​src/​prism/​Evaluator.java Supports rational strings in double and interval parsing.
prism/​src/​io/​UMBImporter.java Converts values according to per-component UMB types.
prism/​src/​io/​ExplicitModelImporter.java Removes the model-wide exactness query.
prism/​src/​explicit/​ExplicitFiles2Model.java Removes the explicit builder’s exactness restriction.
prism-tests/​functionality/​import/​third.umb.auto Exercises rational, mixed-type, and text imports.
prism-tests/​functionality/​import/​third.pm.props Defines expected probability and reward results.
prism-tests/​functionality/​import/​third.pm.orig Supplies the source model for conversion fixtures.
prism-tests/​functionality/​import/​third.exact.trew Adds rational transition rewards.
prism-tests/​functionality/​import/​third.exact.tra Adds rational transition probabilities.
prism-tests/​functionality/​import/​third.exact.sta Adds state definitions for text imports.
prism-tests/​functionality/​import/​third.exact.srew Adds rational state rewards.
prism-tests/​functionality/​import/​third.exact.lab Adds labels for the regression model.
prism-tests/​functionality/​import/​dice.umb.exact.auto Exercises double-valued UMB imports in exact mode.

Review effort: Balanced

@davexparker
davexparker merged commit 1530b99 into prismmodelchecker:master Oct 24, 2026
6 checks passed
@davexparker
davexparker deleted the umb-exact branch October 24, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conversion of exact to floating-point for UMB

2 participants