Skip to content

Commit 03d00df

Browse files
committed
Add restore!
1 parent e89db6a commit 03d00df

File tree

7 files changed

+36
-18
lines changed

7 files changed

+36
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ As a demonstration project, this is not suitable for solving actual linear progr
1313
At present it will fail if:
1414
* The LP is infeasible.
1515
* The LP is unbounded.
16-
* Other unidentified reasons.
16+
* Other unidentified reasons. (In other words, still buggy.)
1717

1818
It is also set up for maximization problems only. To solve a minimization problem use the dual LP by
1919
replacing the inputs `A`, `b`, and `c` with `A'`, `c`, and `b` respectively.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"documenter":{"julia_version":"1.11.4","generation_timestamp":"2025-04-03T11:08:57","documenter_version":"1.10.0"}}
1+
{"documenter":{"julia_version":"1.11.4","generation_timestamp":"2025-04-03T14:12:03","documenter_version":"1.10.0"}}

docs/build/index.html

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

docs/build/objects.inv

11 Bytes
Binary file not shown.

docs/build/search_index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/index.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ julia> lp_solve(T)
123123
1.599999999999999
124124
```
125125

126-
## The `restore` function
126+
## The `restore!` function
127127

128-
As mentioned, the `pivot!` and `pivot_solve!` functions modify the `Tableau`. Use `restore` to return a `Tableau` to its original state like this: `T = restore(T)`.
128+
As mentioned, the `pivot!` and `pivot_solve!` functions modify the `Tableau`. Use `restore!` to return a `Tableau` to its original state like this: `restore!(T)`.
129+
130+
There is also `restore(T)` which does not reset `T`, but creates a new `Tableau` equal to the original state of `T`.
129131

130132
```
131133
julia> T
@@ -150,15 +152,15 @@ julia> T
150152
3 │ 0 29/8 -1/8 0 1 0 9
151153
4 │ 0 -1/4 1/4 0 0 1 6
152154
153-
julia> T = restore(T)
155+
julia> restore!(T)
154156
4×7 DataFrame
155157
Row │ x1 x2 s1 s2 s3 val RHS
156158
│ Exact Exact Exact Exact Exact Exact Exact
157159
─────┼─────────────────────────────────────────────────
158-
1 │ 8 3 1 0 0 0 24
159-
2 │ 1 1 0 1 0 0 4
160-
3 │ 1 4 0 0 1 0 12
161-
4 │ -2 -1 0 0 0 1 0
160+
1 │ 8 3 1/5 -3/5 0 0 12/5
161+
2 │ 1 1 -1/5 8/5 0 0 8/5
162+
3 │ 1 4 3/5 -29/5 1 0 16/5
163+
4 │ 0 0 1/5 2/5 0 1 32/5
162164
```
163165

164166

src/SimpleTableaux.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export Tableau,
2222
pivot_solve,
2323
pivot_solve!,
2424
restore,
25+
restore!,
2526
visualize
2627

2728
"""
@@ -55,12 +56,27 @@ end
5556
5657
Create a new `Tableau` based on the original data used to create `T`.
5758
58-
Recommended usage: `T = restore(T)` to reset `T` to its original state.
59+
See also `restore!`.
5960
"""
6061
function restore(T::Tableau)
6162
return Tableau(T.A, T.b, T.c)
6263
end
6364

65+
"""
66+
restore!(T::Tableau)
67+
68+
Restore a `Tableau` based on the original data used to create it.
69+
"""
70+
function restore!(T::Tableau)
71+
TT = restore(T)
72+
for i in 1:(T.n_cons)
73+
for j in 1:(T.n_vars)
74+
T.M[i, j] = TT.M[i, j]
75+
end
76+
end
77+
return T
78+
end
79+
6480
include("Exact.jl")
6581
include("DataFrame.jl")
6682

0 commit comments

Comments
 (0)