Resolve #11 - #12
Conversation
c9c62c0 to
138c8a9
Compare
…arison operators accordingly
calling is.peek twice at eof sometimes cause is.fail
138c8a9 to
86cb8c2
Compare
MasWag
left a comment
There was a problem hiding this comment.
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 ...) |
There was a problem hiding this comment.
This is likely an unnecessary comment.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This is also likely an unnecessary comment.
| return expr; | ||
| } | ||
|
|
||
| // constraint で ParametricTimingConstraint = Parma_Polyhedra_Library::NNC_Polyhedron の add_constraint する |
There was a problem hiding this comment.
This is also likely an unnecessary comment.
| 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] を生成 |
There was a problem hiding this comment.
This is also likely an unnecessary comment.
There was a problem hiding this comment.
Rewrote it more properly
…alComparison and add decimalCalculation cases
…raint structure and comparison details
86cb8c2 to
2c2ebcf
Compare
There was a problem hiding this comment.
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
TimingConstraintto usedoublefor timestamp values instead ofint - Updated
ParametricTimingConstraintHelperto usePPLRationalfor constants instead ofCoefficient, with proper rational arithmetic operations - Added new equality operators to
PPLRationalclass 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.
| //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); |
There was a problem hiding this comment.
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.
| //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); |
There was a problem hiding this comment.
I wanna keep it for comparison with the parametric_monitor_test
| {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. |
There was a problem hiding this comment.
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.
| //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. |
There was a problem hiding this comment.
Deleted this line and modified the test case
| } | ||
|
|
||
| static inline bool operator==(const PPLRational &lhs, const int &rhs) { | ||
| return lhs.getNumerator() * rhs == lhs.getDenominator(); |
There was a problem hiding this comment.
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.
| return lhs.getNumerator() * rhs == lhs.getDenominator(); | |
| return lhs.getNumerator() == rhs * lhs.getDenominator(); |
There was a problem hiding this comment.
Nice pick! Reflected
| //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); |
There was a problem hiding this comment.
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.
| //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); |
There was a problem hiding this comment.
Same as boolean_monitor_test
…ted index and timestamp for event matching
…nteger and add unit tests for rational comparisons
There was a problem hiding this comment.
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.
operator==(PPLRational, int) has been given, but not the reversed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Close #11.
doubletoTimestampwhen usingdata_parametric_monitorandboolean_monitor,PPLRationalwhen usingparametric_monitorparametric_timing_constraint_helperto handlePPLRational