Skip to content

Resolve #11 - #12

Merged
MasWag merged 14 commits into
MasWag:masterfrom
taiseiKMC:hsaito/issue-11
Jan 9, 2026
Merged

Resolve #11#12
MasWag merged 14 commits into
MasWag:masterfrom
taiseiKMC:hsaito/issue-11

Conversation

@taiseiKMC

@taiseiKMC taiseiKMC commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Close #11.

  • Set double to Timestamp when using data_parametric_monitor and boolean_monitor, PPLRational when using parametric_monitor
  • Update parametric_timing_constraint_helper to handle PPLRational

@taiseiKMC
taiseiKMC force-pushed the hsaito/issue-11 branch 2 times, most recently from c9c62c0 to 138c8a9 Compare December 7, 2025 18:48
calling is.peek twice at eof sometimes cause is.fail

@MasWag MasWag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please remove unnecessary comments.

std::array<std::vector<std::pair<op_t, atom_t>>, 2> tail;
//! @brief comparison in the constraint
comparison_t comparison = comparison_t::EQ;
// (head[0] tail[0][0].first tail[0][0].second ...) comparison (head[1] tail[1][0].first tail[1][0].second ...)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is likely an unnecessary comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved this line to the description part of this struct

void toExpr(const std::size_t parameterSize, const atom_t &atom,
Parma_Polyhedra_Library::Linear_Expression &expr) const {
static auto toExpr(const std::size_t parameterSize, const atom_t &atom) {
// Coefficient は denominator

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is also likely an unnecessary comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed it

return expr;
}

// constraint で ParametricTimingConstraint = Parma_Polyhedra_Library::NNC_Polyhedron の add_constraint する

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is also likely an unnecessary comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed it

void extract(const std::size_t parameterSize, Parma_Polyhedra_Library::Constraint &constraint) const {
std::array<Parma_Polyhedra_Library::Linear_Expression, 2> expr;
std::array<std::pair<Parma_Polyhedra_Library::Linear_Expression, Parma_Polyhedra_Library::Coefficient>, 2> expr;
// head[i], tail[i] から expr[i] を生成

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is also likely an unnecessary comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rewrote it more properly

@taiseiKMC
taiseiKMC marked this pull request as ready for review January 2, 2026 09:19
@MasWag
MasWag requested a review from Copilot January 2, 2026 09:20

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.

Pull request overview

This PR resolves issue #11 by adding support for decimal/non-integer timestamps and rational number constraints in parametric timing constraints. The main changes involve updating TimingConstraint to use double instead of int for timestamps, and migrating ParametricTimingConstraintHelper from using Parma_Polyhedra_Library::Coefficient to PPLRational for handling rational numbers in parametric constraints.

Key Changes:

  • Changed TimingConstraint to use double for timestamp values instead of int
  • Updated ParametricTimingConstraintHelper to use PPLRational for constants instead of Coefficient, with proper rational arithmetic operations
  • Added new equality operators to PPLRational class and improved decimal parsing

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/timing_constraint.hh Changed timestamp type from int to double via Timestamp typedef
src/ppl_rational.hh Fixed decimal parsing loop bug, added equality operators for PPLRational
src/parametric_timing_constraint_helper.hh Migrated from Coefficient to PPLRational for constants, implemented rational arithmetic for expressions
test/timing_constraint_test.cc Added test case for decimal timestamp constraints
test/parametric_timing_constraint_helper_test.cc Updated assertions to use PPLRational, added comprehensive decimal parsing and calculation tests
test/parametric_monitor_test.cc Added test for non-integer timestamps using PPLRational
test/data_parametric_monitor_test.cc Added test fixture and test case for non-integer timestamps with data parametric monitors
test/boolean_monitor_test.cc Refactored tests into namespaces, added non-integer timestamp test case
test/fixture/non_integer_timestamp_fixture.hh New fixture file with three automaton variants for testing non-integer timestamps

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +127 to +128
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.
//BOOST_CHECK_EQUAL(resultVec.size(), 1);

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

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

The commented-out assertion should either be uncommented with the correct expected value or removed entirely. Based on the NOTE comment, it appears the test expects 1 match but the floating-point precision issue causes 2 matches. Since the PR aims to fix decimal timestamp handling with PPLRational, if this test is using doubles (which still have floating-point precision issues), the comment should be clarified or the assertion should be updated to reflect the actual expected behavior.

Suggested change
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.
//BOOST_CHECK_EQUAL(resultVec.size(), 1);
// NOTE: Due to double-precision rounding, 3.3 - 2.1 is evaluated as 1.1999999999999997 < 1.2,
// so both the third and fourth events are matched. This test documents that behavior for doubles.
BOOST_CHECK_EQUAL(resultVec.size(), 2);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanna keep it for comparison with the parametric_monitor_test

Comment thread test/parametric_monitor_test.cc Outdated
{0, {}, {0}, {445, 100}}
};
feed(automaton, std::move(dummyTimedWord));
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

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

The comment is incorrect. It states "3.3 - 2.1 is 1.2" but the actual timestamp used in the test is 325/100 = 3.25, not 3.3. The calculation should be 3.25 - 2.1 = 1.15, which correctly falls within the guard range [1.1, 1.2). The comment should be updated to reflect the actual values used in the test.

Suggested change
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.
// NOTE: The guard range is [1.1, 1.2). The difference 3.25 - 2.1 = 1.15 lies within this range, so the fourth event is also matched.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deleted this line and modified the test case

Comment thread src/ppl_rational.hh Outdated
}

static inline bool operator==(const PPLRational &lhs, const int &rhs) {
return lhs.getNumerator() * rhs == lhs.getDenominator();

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

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

The equality operator implementation is incorrect. When comparing a rational number a/b with an integer c, it should check if a/b == c, which means a == c * b, not a * c == b. The current implementation lhs.getNumerator() * rhs == lhs.getDenominator() checks if numerator times the integer equals the denominator, which is wrong. For example, PPLRational(2, 1) == 2 would evaluate as 2 * 2 == 1 which is false, when it should be true.

Suggested change
return lhs.getNumerator() * rhs == lhs.getDenominator();
return lhs.getNumerator() == rhs * lhs.getDenominator();

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice pick! Reflected

Comment on lines +95 to +96
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.
//BOOST_CHECK_EQUAL(resultVec.size(), 1);

Copilot AI Jan 2, 2026

Copy link

Choose a reason for hiding this comment

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

The commented-out assertion should either be uncommented with the correct expected value or removed entirely. Based on the NOTE comment, it appears the test expects 1 match but the floating-point precision issue causes 2 matches. Since the PR aims to fix decimal timestamp handling with PPLRational, if this test is using doubles (which still have floating-point precision issues), the comment should be clarified or the assertion should be updated to reflect the actual expected behavior.

Suggested change
//NOTE: 3.3 - 2.1 is 1.2, but this is evaluated as 1.1999999999999997 < 1.2, so the fourth event is also matched.
//BOOST_CHECK_EQUAL(resultVec.size(), 1);
// NOTE: With double timestamps, 3.3 - 2.1 could be evaluated as 1.1999999999999997 < 1.2,
// which incorrectly matched the fourth event as well. Using PPLRational timestamps avoids
// this floating-point issue, so only the third event should match.
BOOST_CHECK_EQUAL(resultVec.size(), 1);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as boolean_monitor_test

@MasWag MasWag left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

looks good to me

…nteger and add unit tests for rational comparisons

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ppl_rational.hh
taiseiKMC and others added 2 commits January 8, 2026 01:36
operator==(PPLRational, int) has been given, but not the reversed

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MasWag
MasWag merged commit 1546906 into MasWag:master Jan 9, 2026
3 of 8 checks passed
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.

Support non-integer timing constraints

3 participants