tp_timeconstraint.h
Go to the documentation of this file.
1/** @file tp_timeconstraint.h Classes ClockSet, ElemConstraint and TimeConstraint */
2
3
4
5/* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
6
7 Copyright (C) 2006 B Schlein
8 Copyright (C) 2007 Thomas Moor
9 Exclusive copyright is granted to Klaus Schmidt
10
11*/
12
13#ifndef FAUDES_TP_TIMECONSTRAINT_H
14#define FAUDES_TP_TIMECONSTRAINT_H
15
16#include "corefaudes.h"
17#include "tp_timeinterval.h"
18#include <list>
19
20
21namespace faudes {
22
23
24
25/**
26 * Container class to model a set of clocks.
27 * Technically, this is a NameSet with a static SymbolTable to map
28 * symbolic clock names to clock indices. Thus, clock names are
29 * global similar to event names. Note that clocksets of individual
30 * TtGenerators are assumed to be disjoint.
31 *
32 * Todo: explicitely inherit other constructors (!)
33 *
34 * @ingroup TimedPlugin
35 *
36 */
37
38class FAUDES_API ClockSet : public NameSet {
39
41
42 public:
43
44 /**
45 * Constructor
46 */
47 ClockSet(void);
48
49 /**
50 * Copy-constructor.
51 *
52 * @param rOtherSet
53 * Set to copy
54 */
55 ClockSet(const ClockSet& rOtherSet);
56
57 /**
58 * Construct from file.
59 * Uses the NameSet's Read() function to scan a file for a
60 * specified clockset.
61 *
62 * @param rFilename
63 * File to read
64 * @param rLabel
65 * Section label for the clocks in the file; default value "Clocks"
66 */
67 ClockSet(const std::string& rFilename, const std::string& rLabel = "Clocks");
68
69 /**
70 * Get pointer to static clock SymbolTable
71 * (init on first use pattern)
72 * @return
73 * Pointer to static clock SymbolTable
74 */
75 static SymbolTable* GlobalClockSymbolTablep(void);
76
77 protected:
78
79 /**
80 * Copy from other clock set.
81 *
82 * @param rSourceSet
83 * Destination to copy from
84 */
85 virtual void DoCopy(const ClockSet& rSourceSet);
86
87 /**
88 * Copy from other clock set.
89 *
90 * @param rSourceSet
91 * Destination to copy from
92 */
93 virtual void DoMove(ClockSet& rSourceSet);
94
95 /**
96 * Test equality with other clock set.
97 *
98 * @param rOtherSet
99 * Set to compare with
100 * @return
101 * True/false
102 */
103 virtual bool DoEqual(const ClockSet& rOtherSet) const;
104
105}; // end class ClockSet
106
107
108
109/**
110 * Model of an elementary clock constraint formula. The constraint consists of an index
111 * of a clock, a comperative operator and a constant time value.
112 * Semantically, an elementary contraint is satisfied at a time t if at that time
113 * the clock value compares true with the constant time.
114 * The clock index 0 is used to indicate an invalid contraint. It is only the
115 * context of the more general TimeContraint that provides
116 * a reference to a clock SymbolTable.
117 *
118 * @param mClock
119 * Clock index
120 *
121 * @param mCompOperator
122 * Symbolic integer value for comperative operator
123 *
124 * @param mTimeConstant
125 * Time constant for comparison
126 *
127 * @ingroup TimedPlugin
128 *
129 */
130
132
133 public:
134
135 /**
136 * Typedef for comparison operators in elementary clock constraints
137 *
138 */
139 typedef enum {GreaterEqual, GreaterThan, LessThan, LessEqual} Operator;
140
141 /**
142 * Conversion from symbolic operator to string
143 */
144 static std::string OperatorName(Operator op);
145
146 /**
147 * Construct an (invalid) elementary clock constraint (clockindex 0)
148 *
149 */
150 ElemConstraint(void);
151
152 /**
153 * Construct an elementary clock constraint from values
154 *
155 * @param clockindex
156 * Clock by index.
157 * @param op
158 * Symbolic value for operator
159 * @param timeconst
160 * Value for time constant
161 */
162 ElemConstraint(Idx clockindex, Operator op, Time::Type timeconst);
163
164 /**
165 * Set all values
166 *
167 * @param clockindex
168 * Clock by index.
169 * @param op
170 * Symbolic value for operator
171 * @param timeconst
172 * Value for time constant
173 */
174 void Set(Idx clockindex, Operator op, Time::Type timeconst);
175
176 /**
177 * Set clock by index
178 */
179 Idx Clock(Idx newClock);
180
181 /**
182 * Get clock by index
183 *
184 * @return clock index
185 */
186 Idx Clock(void) const;
187
188 /**
189 * Set operator.
190 *
191 * @param newOp
192 * Symbolic value of new operator
193 */
194 void CompOperator(Operator newOp);
195
196 /**
197 * Get operator
198 * @return Operator
199 */
200 Operator CompOperator(void) const;
201
202 /**
203 * Set time constant.
204 *
205 * @param newTimeConst
206 * Value of new time constant
207 */
208 void TimeConstant(Time::Type newTimeConst);
209
210 /**
211 * Get time constant
212 * @return Time constant
213 */
214 Time::Type TimeConstant(void) const;
215
216 /**
217 * Writes ElemConstraint to std::string
218 *
219 * @return std::string
220 */
221 std::string Str(void) const;
222
223 /**
224 * Test for equality.
225 *
226 * @param otherElemConstraint
227 * Other elementary constraint
228 * @return
229 * True if mClockIndex, mTimeConstant and mCompOperator are equal. Else false.
230 */
231 bool operator== (const ElemConstraint & otherElemConstraint) const;
232
233 /**
234 * Test for equality.
235 *
236 * @param otherElemConstraint
237 * Other elementary constraint
238 * @return
239 * True if not equal; see operator==.
240 */
241 bool operator!= (const ElemConstraint & otherElemConstraint) const;
242
243 /**
244 * Less operator for ordering in container classes
245 *
246 * @param otherElemConstraint
247 * Other ElemConstraint
248 *
249 * @return True when clock index of left constraint is less
250 * than the one of right constraint. Else false.
251 */
252 bool operator < (const ElemConstraint& otherElemConstraint) const;
253
254
255 protected:
256
257 /** Index of clock. */
259
260 /** Comparative operator */
262
263 /** Time constant to compare with clock value */
265
266}; // ElemConstraint
267
268
269
270/**
271 * A TimeConstraint is a set of elementary clock constraints. Semantically,
272 * the elementary constraints are combibed by conjunction, ie the TimeConstraint is
273 * satisfied if all ElemConstraint s are satisfied. This implementation also maintains
274 * the clock symboltable to may cloc indices to symbolic names.
275 *
276 * @param ClockConstraints
277 * Set of elementary clock constraints
278 *
279 * @ingroup TimedPlugin
280 */
281
283
284 public:
285
286 /** Iterator to access ElemConstraints */
287 typedef std::set<ElemConstraint>::const_iterator Iterator;
288
289 /** Reverse iterator to access ElemConstraints */
290 typedef std::set<ElemConstraint>::const_reverse_iterator RIterator;
291
292 /** Convenience typedef for operators */
294
295 /**
296 * Construct an empty TimeConstraint (allways satisfied)
297 */
298 TimeConstraint(void);
299
300 /**
301 * Copy constructor
302 *
303 * @param rOtherTimeConstraint
304 * Time constraint to copy
305 */
306 TimeConstraint(const TimeConstraint& rOtherTimeConstraint);
307
308 /**
309 * Constructor from file.
310 *
311 * Uses Read() to scan a file for specified label to read the constraint.
312 *
313 * @param rFilename
314 * File to read
315 * @param rLabel
316 * Section label for the set in the file.
317 */
318 TimeConstraint(const std::string& rFilename, const std::string& rLabel = "TimeConstraint");
319
320 /**
321 * Destructor
322 */
323 ~TimeConstraint(void);
324
325
326 /**
327 * Get Pointer to mpClockSymbolTable.
328 *
329 * @return
330 * Pointer to mpClockSymbolTable
331 */
332 SymbolTable* ClockSymbolTablep(void) const;
333
334
335 /**
336 * Set Pointer to mpClockSymbolTable.
337 *
338 */
339 void ClockSymbolTablep(SymbolTable* pSymTab);
340
341 /**
342 * Write to console
343 */
344 void Write(void) const;
345
346 /**
347 * Write to file with label (default: "TimeConstraint") and
348 * openmode (default: truncate file).
349 *
350 * @param rFileName
351 * Filename
352 * @param rLabel
353 * Label for set in file
354 * @param openmode
355 * std::ios::openmode
356 *
357 * @exception Exception
358 * If opening/writing fails an Exception object is thrown (id 2)
359 */
360 void Write(const std::string& rFileName, const std::string& rLabel = "TimeConstraint",
361 std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
362
363
364 /**
365 * Write to TokenWriter. The name of the constraint is used
366 * as the label in the file.
367 *
368 * @param tw
369 * Reference to TokenWriter
370 *
371 * @exception std::ios::failure
372 * Thrown on i/o error.
373 */
374 void Write(TokenWriter& tw) const;
375
376 /**
377 * Write to TokenWriter with a given label
378 *
379 * @param tw
380 * Reference to TokenWriter
381 * @param rLabel
382 * Label for set in file
383 *
384 * @exception std::ios::failure
385 * Thrown on i/o error.
386 */
387 void Write(TokenWriter& tw, const std::string& rLabel) const;
388
389 /**
390 * Write to a std::string
391 *
392 * @return
393 * String containing all elements
394 */
395 std::string ToString(void) const;
396
397 /**
398 * Write NameSet to console, debug version
399 */
400 void DWrite(void) const;
401
402 /** Write to TokenWriter, debug version
403 *
404 * @param tw
405 * Reference to TokenWriter
406 *
407 * @exception std::ios::failure
408 * Thrown on i/o error.
409 */
410 void DWrite(TokenWriter& tw) const;
411
412 /**
413 * Read from file. Reads specified label by creating a tokenreader and
414 * calling read(tr)
415 *
416 * @param rFileName
417 * Filename
418 * @param rLabel
419 * token label to read from file
420 *
421 * @exception Exception
422 * If opening/reading fails an Exception object is thrown (id 1, 50, 51, 56)
423 */
424 void Read(const std::string& rFileName, const std::string& rLabel = "TimeConstraint");
425
426
427 /**
428 * Read from tokenreader. Clears before. It is an error
429 * if the file contains an index
430 *
431 * @param tr
432 * Reference to tokenreader
433 * @param rLabel
434 * Label to read
435 *
436 * @exception std::ios::failure
437 * Thrown on i/o error.
438 */
439 void Read(TokenReader& tr, const std::string& rLabel = "TimeConstraint");
440
441
442 /**
443 * Return name of Constraint
444 *
445 * @return
446 * Name
447 */
448 std::string Name(void) const { return mName;};
449
450 /**
451 * Set name of Constraint
452 *
453 * @param rName
454 * BaseSet name
455 */
456 void Name(const std::string& rName) { mName=rName; };
457
458
459 /**
460 * Checks if TimeConstraint containts no ElemConstraints
461 *
462 * @return
463 * True if TimeConstraint is empty. Else false.
464 */
465 bool Empty(void) const;
466
467 /**
468 * Returns number of ElemConstraint s.
469 *
470 * @return Number of ElemConstraint s.
471 */
472 Idx Size(void) const;
473
474 /**
475 * Adds an elementary clock constraint to the time constraint.
476 *
477 * @param rElemConstr
478 * Elementary clock constraint that is to be added to time constraint
479 * @return
480 * iterator to new constraint
481 */
482 Iterator Insert(const ElemConstraint& rElemConstr);
483
484 /**
485 * Adds an elementary clock constraint to the time constraint.
486 *
487 * @param clockname
488 * Clock for new ElemConstraint
489 * @param op
490 * Operator for new ElemConstraint
491 * @param timeconst
492 * Time constant for new ElemConstraint
493 * @return
494 * iterator to new constraint
495 */
496 Iterator Insert(const std::string clockname, Operator op, const Time::Type timeconst);
497
498 /**
499 * Adds an elementary clock constraint to the time constraint.
500 *
501 * @param clockindex
502 * Clock for new ElemConstraint
503 * @param op
504 * Operator for new ElemConstraint
505 * @param timeconst
506 * Time constant for new ElemConstraint
507 * @return
508 * iterator to new constraint
509 */
510 Iterator Insert(Idx clockindex, Operator op, const Time::Type timeconst);
511
512 /**
513 * Adds a list of elementary clock constraints to the time constraint.
514 *
515 * @param rNewConstraints
516 * Set of elementary clock constraints that is to be added to time constraint.
517 */
518 void Insert(const std::list<ElemConstraint>& rNewConstraints);
519
520 /**
521 * Adds elementary clock constraints from other TimeConstant to the time constraint.
522 *
523 * @param rOtherTimeConstraint
524 * Time constraint whos clock constraints are to be added to time constraint.
525 */
526 void Insert(const TimeConstraint& rOtherTimeConstraint);
527
528 /**
529 * Convenience operator to combine a TimeConstraint with another TimeConstraint.
530 *
531 * @param rOtherTimeConstraint
532 * other TimeConstraint
533 *
534 * @return TimeConstraint object containing all ElemConstraints of both TimeConstraints.
535 */
536 TimeConstraint& operator << (const TimeConstraint& rOtherTimeConstraint) {
537 this->Insert(rOtherTimeConstraint); return *this; };
538
539 /**
540 * Convenience operator to combines a TimeConstraint with an elementary TimeConstraint.
541 *
542 * @param rElemConstr
543 * extra elemtary constraint
544 *
545 * @return TimeConstraint object containing all ElemConstraints of both TimeConstraints.
546 */
547 TimeConstraint& operator << (const ElemConstraint& rElemConstr) {
548 this->Insert(rElemConstr); return *this; };
549
550 /**
551 * Returns copy of ClockConstraints
552 */
553 std::set<ElemConstraint> ClockConstraints(void) const;
554
555 /**
556 * Advertise clock to ClockSymbolTable and retrive index
557 *
558 * @param rClockName
559 * symbolic name of clock
560 *
561 * @return
562 * index of clock
563 */
564 Idx InsClock(const std::string& rClockName) const;
565
566 /**
567 * Lookup clock name
568 *
569 * @param clockindex
570 * index of clock
571 *
572 * @return
573 * name of clock
574 */
575 std::string ClockName(Idx clockindex) const;
576
577 /**
578 * Lookup clock index
579 *
580 * @param rClockName
581 * Symbolic name of clock
582 *
583 * @return
584 * Index of clock
585 */
586 Idx ClockIndex(const std::string& rClockName) const;
587
588 /**
589 * Pretty printable string of elem. constraint
590 *
591 * @param rElemConstr
592 * ref to elem constraint
593 *
594 * @return
595 * output string
596 */
597 std::string EStr(const ElemConstraint& rElemConstr) const;
598
599 /**
600 * Removes all elementary clock constraints refering to a specified clock.
601 *
602 * @param clock
603 * Clock whos constraints are to be removed.
604 * @return
605 * True, if constraints(s) have been erased
606 */
607 bool EraseByClock(Idx clock);
608
609 /**
610 * Calls std::set::erase(iterator). ElemConstraint refered by it is removed from constraint.
611 *
612 * @param it
613 * TimeConstraint::Iterator pointing to ElemConstraint that is removed.
614 *
615 * @return
616 * Iterator pointing to next ElemConstraint.
617 */
618 Iterator Erase(Iterator it);
619
620 /**
621 * Removes elementary clock constraint.
622 *
623 * @param rElemConstr
624 * Constraint to be removed.
625 * @return
626 * True, if constraint has been removed
627 */
628 bool Erase(const ElemConstraint& rElemConstr);
629
630 /**
631 * Removes elementary clock constraint.
632 *
633 * @param rClockName
634 * Clock
635 * @param op
636 * Operator
637 * @param timeconst
638 * Time constant
639 * @return
640 * True, if constraint has been removed
641 */
642 bool Erase(const std::string& rClockName, Operator op, const Time::Type timeconst);
643
644 /**
645 * Removes elementary clock constraint.
646 *
647 * @param clockindex
648 * Clock
649 * @param op
650 * Operator
651 * @param timeconst
652 * Time constant
653 * @return
654 * True, if constraint has been removed
655 */
656 bool Erase(Idx clockindex, Operator op, const Time::Type timeconst);
657
658 /**
659 * Clear all
660 */
661 void Clear(void);
662
663
664 /**
665 * Checks if elementary clock constraint is contained in constraint
666 *
667 * @param rElemConstr
668 * elementary constraint
669 */
670 bool Exists(const ElemConstraint& rElemConstr) const;
671
672 /**
673 * Iterator to begin of set
674 *
675 * @return
676 * TimeConstraint::Iterator
677 */
678 Iterator Begin(void) const;
679
680 /**
681 * Iterator to end of set
682 *
683 * @return
684 * TimeConstraint::Iterator
685 */
686 Iterator End(void) const;
687
688 /**
689 * Reverse iterator that yields the ElemConstraints in reverse order starting at
690 * the last element and ending after the first. See set<...>::rbegin(void).
691 * Returns the "End".
692 *
693 * @return
694 * TimeConstraint::RIterator
695 */
696 RIterator RBegin(void) const;
697
698 /**
699 * Reverse iterator that yields the ElemConstraints in reverse order starting at
700 * the last element and ending after the first. See set<...>::rend(void).
701 * Returns the "Begin".
702 *
703 * @return
704 * TimeConstraint::RIterator
705 */
706 RIterator REnd(void) const;
707
708 /**
709 * Iterator to first constraint with specified clock
710 *
711 * @return
712 * TimeConstraint::iterator
713 */
714 Iterator Begin(Idx clock) const;
715
716 /**
717 * Iterator to first constraint just behind specified clock
718 *
719 * @return
720 * TimeConstraint::Iterator
721 */
722 Iterator End(Idx clock) const;
723
724 /**
725 * Returns a Clockset containing all clocks used
726 * by the TimeConstraint.
727 *
728 * @return Clockset containing all clocks used by the TimeConstraint.
729 */
730 ClockSet ActiveClocks(void) const;
731
732 /**
733 * Given a clock, compute the timeinterval in which
734 * the constraint is satisfied
735 *
736 * @return TimeInterval
737 */
738 TimeInterval Interval(Idx clockindex) const;
739
740 /**
741 * Given a clock, compute the timeinterval in which
742 * the constraint is satisfied
743 *
744 * @return TimeInterval
745 */
746 TimeInterval Interval(const std::string& clockname) const;
747
748 /**
749 * Given a clock and an interval, set up the constraint such
750 * that it is valid in the given interval.
751 *
752 * @param clockindex
753 * specifies the clock
754 * @param rInterval
755 * reference to time interval
756 */
757 void Interval(Idx clockindex, const TimeInterval& rInterval);
758
759
760 /**
761 * Given a clock and an interval, set up the constraint such
762 * that it is valid in the given interval.
763 *
764 * @param rClockName
765 * specifies the clock
766 * @param rInterval
767 * reference to time interval
768 */
769 void Interval(const std::string& rClockName, const TimeInterval& rInterval);
770
771 /**
772 * Minimize by eliminating redundant elementary constraints. The current implemantation
773 * retrieves the time constraints as intervals per clock and then converts back to
774 * a time constraint.
775 */
776 void Minimize(void);
777
778
779 /**
780 * Test for equality.
781 * The implementation converts both constraints to intervals and then
782 * performs the comparison.
783 *
784 * @param rOther
785 * Constraint to compare with.
786 * @return
787 * True if constraints are semantically identical.
788 */
789 bool operator== (const TimeConstraint& rOther) const;
790
791 /**
792 * Test for equality.
793 *
794 * @param rOther
795 * Constraint to compare with.
796 * @return
797 * True if not equal; see operator==.
798 */
799 bool operator!= (const TimeConstraint & rOther) const;
800
801 protected:
802
803 /** My name */
804 std::string mName;
805
806 /** Set of elementary clock constraints */
807 std::set<ElemConstraint> mClockConstraints;
808
809 /** SymbolTable for clock names */
811
812 /** nonconst iterator to access ElemConstraints */
813 typedef std::set<ElemConstraint>::iterator iterator;
814
815}; //TimeConstraint
816
817
818} // namespace faudes
819
820
821#endif
822
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
void Name(const std::string &rName)
std::set< ElemConstraint >::const_iterator Iterator
std::set< ElemConstraint > mClockConstraints
ElemConstraint::Operator Operator
std::set< ElemConstraint >::const_reverse_iterator RIterator
std::string Name(void) const
std::set< ElemConstraint >::iterator iterator
uint32_t Idx

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen