tp_timeinterval.cpp
Go to the documentation of this file.
1 /* tp_timeinterval.cpp -- model of interval */
2 
3 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2007 Ruediger Berndt
6  Copyright (C) 2007 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9 */
10 
11 #include "tp_timeinterval.h"
12 
13 using namespace faudes;
14 
15 
16 
17 /* canonical */
19  // make left closed
20  if((!mbLBincl)&&(!LBinf())) {
21  LB(mstLB+Time::Step());
22  LBincl(true);
23  }
24  // make right open
25  if(UBincl()) {
26  UB(mstLB+Time::Step());
27  UBincl(false);
28  }
29 }
30 
31 /* bool Empty const() */
32 bool TimeInterval::Empty() const {
33  if(mstLB<mstUB)
34  return false;
35  if(mstLB==mstUB)
36  if((mbLBincl==true) && (mbUBincl==true))
37  return false;
38  return true;
39 }
40 
41 /* bool In(time) */
42 bool TimeInterval::In(Time::Type time) const {
43  if(time<mstLB) return false;
44  if(time> mstUB) return false;
45  if(time == mstLB) if( ! mbLBincl) return false;
46  if(time == mstUB) if(! mbUBincl) return false;
47  return true;
48 }
49 
50 /* PositiveLeftShift */
52  if(!UBinf()) UB(mstUB-time);
53  if(!LBinf()) LB(mstLB-time);
54  if( LBinf() || mstLB <= 0){
55  LB(0);
56  mbLBincl=true;
57  }
58 }
59 
60 /* std::string Str() const */
61 std::string TimeInterval::Str(void) const {
62 
63  std::string res;
64  std::stringstream resstream;
65 
66  if(Empty()) {
67  resstream << "[empty]";
68  res=resstream.str();
69  return(res);
70  }
71 
72  if(mbLBincl) resstream << "[";
73  else resstream << "(";
74  if(LBinf()) resstream << "-inf";
75  else resstream << mstLB;
76  resstream << ", ";
77  if(UBinf()) resstream << "inf";
78  else resstream << mstUB;
79  if(mbUBincl) resstream << "]";
80  else resstream << ")";
81  res=resstream.str();
82  return(res);
83 
84 }
85 
86 /* void Intersect(const TimeInterval& rOtherInterval) */
87 void TimeInterval::Intersect(const TimeInterval& rOtherInterval) {
88 
89  FD_DC("TimeInterval::Intersect(otherinterval): " << Str()<<" & " <<
90  rOtherInterval.Str() );
91 
92  // other upper bound matches
93  if(UB()==rOtherInterval.UB()) {
94  if(!rOtherInterval.UBincl()) UBincl(false);
95  }
96  // other upper bound wins
97  if(UB() > rOtherInterval.UB()) {
98  UB(rOtherInterval.UB());
99  UBincl(rOtherInterval.UBincl());
100  }
101  // other lower bound matches
102  if(LB()==rOtherInterval.LB()) {
103  if(!rOtherInterval.LBincl()) LBincl(false);
104  }
105  // other lower bound wins
106  if(LB() < rOtherInterval.LB()) {
107  LB(rOtherInterval.LB());
108  LBincl(rOtherInterval.LBincl());
109  }
110 
111  FD_DC("TimeInterval::Intersect( ... ), ret: " << Str());
112 }
113 
114 
115 /* TimeInterval Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
116 TimeInterval TimeInterval::Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
117  FD_DC("TimeInterval::Intersect(" << rInterval1.Str()<<", " <<
118  rInterval2.Str() << ")");
119  TimeInterval res=rInterval1;
120  res.Intersect(rInterval2);
121  FD_DC("TimeInterval::Intersect( ... ), ret: " << res.Str());
122  return(res);
123 }
124 
125 
126 /* void Merge(const TimeInterval& rOtherInterval) */
127 void TimeInterval::Merge(const TimeInterval& rOtherInterval) {
128  // other upper bound matches
129  if(UB()==rOtherInterval.UB()) {
130  if(rOtherInterval.UBincl()) UBincl(true);
131  }
132  // other upper bound wins
133  if(UB() < rOtherInterval.UB()) {
134  UB(rOtherInterval.UB());
135  UBincl(rOtherInterval.UBincl());
136  }
137  // other lower bound matches
138  if(LB()==rOtherInterval.LB()) {
139  if(rOtherInterval.LBincl() ) LBincl(true);
140  }
141  // other lower bound wins
142  if(LB()<rOtherInterval.LB()) {
143  LB(rOtherInterval.LB());
144  LBincl(rOtherInterval.LBincl());
145  }
146 }
147 
148 /* TimeInterval Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
149 TimeInterval TimeInterval::Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
150  TimeInterval res=rInterval1;
151  res.Merge(rInterval2);
152  return res;
153 }
#define FD_DC(message)
Debug: optional report on container operations.
Model of a time interval.
void LB(Time::Type time)
Set the lower bound to a given value.
void Merge(const TimeInterval &rOtherInterval)
Merge this interval with other interval.
Time::Type LB(void) const
Return lower bound.
Time::Type mstLB
Lower bound.
bool LBincl(void) const
Test for lower bound inclusive.
void PositiveLeftShift(Time::Type time)
Transform by left shift and intersection with [0, inf)
void Canonical(void)
Convert to canonical representation.
Time::Type UB(void) const
Return upper bound.
bool UBinf(void) const
Test for upper bound infinity.
Time::Type mstUB
Upper bound.
bool UBincl(void) const
Test for upper bound inclusive.
bool In(Time::Type time) const
Test whether a point satisfies interval.
std::string Str(void) const
Pretty printable string.
void UBincl(bool incl)
Configures the upper bound to be inclusive.
void LBincl(bool incl)
Configures the lower bound to be inclusive.
void UB(Time::Type time)
Set the upper bound to a given value.
bool mbUBincl
Flag to indicate that the upper bound is part of the interval.
bool LBinf(void) const
Test for lower bound infinity.
bool mbLBincl
Flag to indicate that lower boundary is part of the interval.
bool Empty(void) const
Test interval for empty set.
void Intersect(const TimeInterval &rOtherInterval)
Intersect this interval with other interval.
Int Type
Datatype for point on time axis.
static Type Step(void)
Smallest representable time step.
libFAUDES resides within the namespace faudes.
Class TimeInterval.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen