All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Semirings.h
Go to the documentation of this file.
1 /*
2  * Semirings.h
3  *
4  * Created on: May 31, 2016
5  * Author: Michael Wegner (michael.wegner@student.kit.edu)
6  */
7 
8 #ifndef NETWORKIT_CPP_ALGEBRAIC_SEMIRINGS_H_
9 #define NETWORKIT_CPP_ALGEBRAIC_SEMIRINGS_H_
10 
11 #include <algorithm>
12 
13 // *****************************************************
14 // Semiring Definitions
15 // *****************************************************
16 
26 public:
27  ArithmeticSemiring() = default;
28  virtual ~ArithmeticSemiring() = default;
29 
30  inline static double add(double a, double b) {
31  return a + b;
32  }
33 
34  inline static double mult(double a, double b) {
35  return a * b;
36  }
37 
38  inline static double zero() {return 0;};
39 
40  inline static double one() {return 1;};
41 };
42 
52 public:
53  MinPlusSemiring() = default;
54  virtual ~MinPlusSemiring() = default;
55 
56  inline static double add(double a, double b) {
57  return std::min(a,b);
58  }
59 
60  inline static double mult(double a, double b) {
61  return a+b;
62  }
63 
64  inline static double zero() {return std::numeric_limits<double>::infinity();};
65 
66  inline static double one() {return 0;};
67 };
68 
78 public:
79  MaxPlusSemiring() = default;
80  virtual ~MaxPlusSemiring() = default;
81 
82  inline static double add(double a, double b) {
83  return std::max(a,b);
84  }
85 
86  inline static double mult(double a, double b) {
87  return a+b;
88  }
89 
90  inline static double zero() {return -std::numeric_limits<double>::infinity();};
91 
92  inline static double one() {return 0;};
93 };
94 
104 public:
105  MinMaxSemiring() = default;
106  virtual ~MinMaxSemiring() = default;
107 
108  inline static double add(double a, double b) {
109  return std::min(a,b);
110  }
111 
112  inline static double mult(double a, double b) {
113  return std::max(a,b);
114  }
115 
116  inline static double zero() {return std::numeric_limits<double>::infinity();};
117 
118  inline static double one() {return -std::numeric_limits<double>::infinity();};
119 };
120 
130 public:
131  MaxMinSemiring() = default;
132  virtual ~MaxMinSemiring() = default;
133 
134  inline static double add(double a, double b) {
135  return std::max(a,b);
136  }
137 
138  inline static double mult(double a, double b) {
139  return std::min(a,b);
140  }
141 
142  inline static double zero() {return -std::numeric_limits<double>::infinity();};
143 
144  inline static double one() {return 0;};
145 };
146 
156 public:
157  IntLogicalSemiring() = default;
158  virtual ~IntLogicalSemiring() = default;
159 
160  inline static double add(double a, double b) {
161  return (int) a || (int) b;
162  }
163 
164  inline static double mult(double a, double b) {
165  return (int) a && (int) b;
166  }
167 
168  inline static double zero() {return 0;};
169 
170  inline static double one() {return 1;};
171 };
172 
182 public:
183  GaloisFieldSemiring() = default;
184  virtual ~GaloisFieldSemiring() = default;
185 
186  inline static double add(double a, double b) {
187  return (int) a ^ (int) b;
188  }
189 
190  inline static double mult(double a, double b) {
191  return (int) a & (int) b;
192  }
193 
194  inline static double zero() {return 0;};
195 
196  inline static double one() {return 1;};
197 };
198 
199 
200 
201 #endif /* NETWORKIT_CPP_ALGEBRAIC_SEMIRINGS_H_ */
MinMaxSemiring()=default
MinPlusSemiring()=default
add: min mult: arithmetic add zero: +infty one: 0 codomain = (-infty, +infty]
Definition: Semirings.h:51
static double one()
Definition: Semirings.h:144
add: max mult: arithmetic add zero: -infty one: 0 codomain = [-infty, +infty)
Definition: Semirings.h:77
static double mult(double a, double b)
Definition: Semirings.h:164
static double zero()
Definition: Semirings.h:38
virtual ~IntLogicalSemiring()=default
virtual ~GaloisFieldSemiring()=default
MaxMinSemiring()=default
static double mult(double a, double b)
Definition: Semirings.h:34
static double mult(double a, double b)
Definition: Semirings.h:190
static double zero()
Definition: Semirings.h:194
static double zero()
Definition: Semirings.h:116
GaloisFieldSemiring()=default
static double zero()
Definition: Semirings.h:142
static double one()
Definition: Semirings.h:196
static double add(double a, double b)
Definition: Semirings.h:134
static double zero()
Definition: Semirings.h:90
static double mult(double a, double b)
Definition: Semirings.h:60
static double mult(double a, double b)
Definition: Semirings.h:138
static double zero()
Definition: Semirings.h:168
MaxPlusSemiring()=default
add: min mult: max zero: +infty one: -infty codomain = [-infty, +infty]
Definition: Semirings.h:103
static double one()
Definition: Semirings.h:92
static double one()
Definition: Semirings.h:66
static double add(double a, double b)
Definition: Semirings.h:186
ArithmeticSemiring()=default
IntLogicalSemiring()=default
static double add(double a, double b)
Definition: Semirings.h:30
static double one()
Definition: Semirings.h:40
add: arithmetic add mult: arithmetic multiplication zero: 0 one: 1 codomain = (-infty, +infty)
Definition: Semirings.h:25
virtual ~MinMaxSemiring()=default
static double add(double a, double b)
Definition: Semirings.h:82
static double add(double a, double b)
Definition: Semirings.h:56
static double add(double a, double b)
Definition: Semirings.h:108
add: logical or mult: logical and zero: 0 one: 1 codomain = [-infty, +infty]
Definition: Semirings.h:155
virtual ~MinPlusSemiring()=default
virtual ~MaxMinSemiring()=default
static double zero()
Definition: Semirings.h:64
add: xor mult: bitwise and zero: 0 one: 1 codomain = [0, 1]
Definition: Semirings.h:181
static double one()
Definition: Semirings.h:170
static double mult(double a, double b)
Definition: Semirings.h:86
virtual ~MaxPlusSemiring()=default
static double one()
Definition: Semirings.h:118
static double mult(double a, double b)
Definition: Semirings.h:112
virtual ~ArithmeticSemiring()=default
static double add(double a, double b)
Definition: Semirings.h:160
add: max mult: min zero: -infty one: +infty codomain = [-infty, +infty]
Definition: Semirings.h:129