SOLA
Loading...
Searching...
No Matches
fuzzy_value.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef MINHTON_ALGORITHMS_ESEARCH_FUZZY_VALUE_H_
8#define MINHTON_ALGORITHMS_ESEARCH_FUZZY_VALUE_H_
9
10#include <ostream>
11
12namespace minhton {
13
15public:
16 static FuzzyValue createFalse() { return FuzzyValue(kFalse); }
17 static FuzzyValue createUndecided() { return FuzzyValue(kUndecided); }
18 static FuzzyValue createTrue() { return FuzzyValue(kTrue); }
19
20 bool isFalse() const { return value_ == kFalse; }
21
22 bool isUndecided() const { return value_ == kUndecided; }
23
24 bool isTrue() const { return value_ == kTrue; }
25
26 friend std::ostream &operator<<(std::ostream &os, const FuzzyValue &fuzz) {
27 if (fuzz.isFalse()) {
28 os << "false";
29 return os;
30 }
31
32 if (fuzz.isUndecided()) {
33 os << "undecided";
34 return os;
35 }
36
37 if (fuzz.isTrue()) {
38 os << "true";
39 return os;
40 }
41
42 os << "invalid";
43 return os;
44 }
45
46 FuzzyValue operator!() const { return FuzzyValue(kTrue - value_); }
47
48 FuzzyValue operator&&(FuzzyValue other) const {
49 return FuzzyValue(std::min(this->value_, other.value_));
50 }
51
52 FuzzyValue operator||(FuzzyValue other) const {
53 return FuzzyValue(std::max(this->value_, other.value_));
54 }
55
56 bool operator==(FuzzyValue other) const { return this->value_ == other.value_; }
57
58 bool operator!=(FuzzyValue other) const { return this->value_ != other.value_; }
59
60private:
61 static const short kFalse = 0;
62 static const short kUndecided = 1;
63 static const short kTrue = 2;
64
65 explicit FuzzyValue(short value) : value_(value){};
66
67 short value_;
68};
69
70} // namespace minhton
71
72#endif
Definition fuzzy_value.h:14
Definition minhton_watchdog_ns3.cpp:24