-
Notifications
You must be signed in to change notification settings - Fork 0
/
Properties.cs
217 lines (176 loc) · 6.11 KB
/
Properties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gurobi;
using Tools.IO;
using Metabolism.Patterns;
using Tools.Converter.Biology;
namespace Metabolism.Analysis
{
/// <summary>
/// This interface you to add two coordinates I and J to a class. Afterwards you can sort objects of this type e.g. lexicographically.
/// </summary>
public interface IPair<T> : IComparable<T> where T : IPair<T>
{
int I { get; }
int J { get; }
}
/// <summary>
/// This interface allows to create a class that tests whether a certain property holds for a flux pattern "a". E.g. $5 \notin a$.
/// </summary>
public interface ILatticeProperty
{
/// <summary>
/// Tests whether a flux pattern "a" fulfills the classes property.
/// </summary>
/// <param name="a">The pattern you want to test.</param>
/// <returns>true iff "a" fulfills the property.</returns>
bool HoldsFor<FP>(FP a) where FP : IFluxPattern<FP>;
}
/// <summary>
/// A property that has to hold for a flux pattern "a" if $I \notin a$
/// </summary>
public interface INoIImpliesProperty : ILatticeProperty
{
/// <summary>
/// The coordinate relevant for the property.
/// </summary>
int I { get; }
string ToString(String[] reaction_names);
}
/// <summary>
/// A pair of two coordinates. You can order a set of Pair objects lexicographically.
/// </summary>
public class Pair<T> : IPair<T> where T : Pair<T>
{
public readonly int i, j;
/// <summary>
/// Creates a new Pair object for the fixed coordinates "i" and "j".
/// </summary>
public Pair(int i, int j)
{
this.i = i;
this.j = j;
}
public int I
{
get { return i; }
}
public int J
{
get { return j; }
}
/// <summary>
/// Lexicographical ordering of Pair objects.
/// </summary>
public int CompareTo(T other)
{
if (this.i != other.i)
return this.i < other.i ? -1 : 1;
if (this.j != other.j)
return this.j < other.j ? -1 : 1;
return 0;
}
public override string ToString()
{
return String.Format("({0}, {1})", i + 1, j + 1);
}
public string ToString(String[] reaction_names)
{
return String.Format("({0}, {1})", reaction_names[i], reaction_names[j]);
}
public override int GetHashCode()
{
return this.ToString().GetHashCode();
}
}
/// <summary>
/// An abstract class that tests whether a flux pattern "a" fulfills a property regarding a pair (i,j) of coordinates.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class LatticePropertyPair<T> : Pair<T>, ILatticeProperty where T : LatticePropertyPair<T>
{
/// <summary>
/// Creates an instance of the class for the fixed coordinates (i,j)
/// </summary>
public LatticePropertyPair(int i, int j) : base(i, j) { }
public abstract bool HoldsFor<FP>(FP a) where FP : IFluxPattern<FP>;
}
/// <summary>
/// A pair (i,j) of coordinates that represents flux coupling $i \rightarrow j$ for the flux lattice.
/// </summary>
public class Couple : LatticePropertyPair<Couple>, INoIImpliesProperty
{
public Couple(int i, int j) : base(i, j) { }
public override string ToString()
{
return String.Format("{0} -> {1}", i + 1, j + 1);
}
public string ToString(String[] reaction_names)
{
return String.Format("{0} -> {1}", reaction_names[i], reaction_names[j]);
}
public override int GetHashCode()
{
return this.ToString().GetHashCode();
}
/// <summary>
/// Tests whether $i \rightarrow j$ holds for the flux pattern "a".
/// </summary>
public override bool HoldsFor<FP>(FP a)
{
return !a[j] || a[i] || a.Count == 0;
}
}
/// <summary>
/// A pair (i,j) of coordinates that represents partial flux coupling $i \leftrightarrow j$ for the flux lattice.
/// </summary>
public class PartialCouple : Couple
{
public PartialCouple(int i, int j) : base(Math.Min(i, j), Math.Max(i, j)) { }
public override string ToString()
{
return String.Format("{0} <-> {1}", i + 1, j + 1);
}
public string ToString(String[] reaction_names)
{
return String.Format("{0} -> {1}\n{1} -> {0}", reaction_names[i], reaction_names[j]);
}
/// <summary>
/// Tests whether $i \leftrightarrow j$ holds for the flux pattern "a".
/// </summary>
public override bool HoldsFor<FP>(FP a)
{
return a[j] == a[i];
}
}
/// <summary>
/// A pair (i,j) of coordinates that represents fully flux coupling $i \leftrightarrow_\lambda j$ for the flux lattice.
/// </summary>
public class FullCouple : PartialCouple
{
public readonly double lambda_i, lambda_j;
/// <summary>
/// Creates a new instance of the class.
/// </summary>
/// <remarks>
/// $lambda_i f_i = lambda_j f_j \forall f \in F$.
/// The "HoldsFor" method only test for partial coupling!
/// </remarks>
public FullCouple(int i, int j, double lambda_i, double lambda_j)
: base(i, j)
{
this.lambda_i = i < j ? lambda_i : lambda_j;
this.lambda_j = i < j ? lambda_j : lambda_i;
}
public override string ToString()
{
return String.Format("{0} <-> {1} ({2:0.0###} : {3:0.0###})", i + 1, j + 1, lambda_i, lambda_j);
}
public string ToString(String[] reaction_names)
{
return String.Format("{0} <-> {1} ({2:0.0###} : {3:0.0###})", reaction_names[i], reaction_names[j], lambda_i, lambda_j);
}
}
}