Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
373 commits
Select commit Hold shift + click to select a range
efe45bb
cleanup
discocube Mar 14, 2023
3ee7a68
cleanup
discocube Mar 14, 2023
b2bbfe1
cleanup
discocube Mar 14, 2023
000b8ad
cleanup
discocube Mar 15, 2023
700e63c
cleanup
discocube Mar 15, 2023
7ff247b
cleanup
discocube Mar 15, 2023
8a5ab13
cleanup
discocube Mar 15, 2023
4e4aec7
cleanup
discocube Mar 15, 2023
eddeb65
cleanup
discocube Mar 15, 2023
c95b30e
cleanup
discocube Mar 15, 2023
ea4710d
cleanup
discocube Mar 15, 2023
cc2a644
cleanup
discocube Mar 16, 2023
9a51862
cleanup
discocube Mar 16, 2023
d0f7209
cleanup
discocube Mar 16, 2023
69db7cb
cleanup
discocube Mar 16, 2023
8e860fe
cleanup
discocube Mar 16, 2023
8e9189c
cleanup
discocube Mar 16, 2023
00d9223
cleanup
discocube Mar 16, 2023
e0c280f
cleanup
discocube Mar 16, 2023
9e19f5f
fixed memory leak.
discocube Mar 16, 2023
2e0d0f6
fixed memory leak.
discocube Mar 16, 2023
06bb6fc
update
discocube Mar 16, 2023
c0626c0
still unsure about the docstring.
discocube Mar 16, 2023
d471716
still unsure about the docstring.
discocube Mar 16, 2023
45d93db
still unsure about the docstring.
discocube Mar 16, 2023
70a856f
updated solution times.
discocube Mar 16, 2023
6dc2d6d
updated solution times.
discocube Mar 16, 2023
f44881a
updated solution times.
discocube Mar 16, 2023
a98f0c1
updated solution times.
discocube Mar 16, 2023
f29bc43
updated solution times.
discocube Mar 16, 2023
a91e7fe
updated solution times.
discocube Mar 16, 2023
9b14051
updated solution times.
discocube Mar 16, 2023
6400638
Cleanup
discocube Mar 17, 2023
c5e5fce
updated solution times.
discocube Mar 17, 2023
c06027d
updated solution times.
discocube Mar 17, 2023
732421f
updated solution times.
discocube Mar 17, 2023
cf701e1
updated solution times.
discocube Mar 17, 2023
542f5ca
updated solution times.
discocube Mar 17, 2023
7c18f69
updated solution times.
discocube Mar 17, 2023
8e707b8
updated solution times.
discocube Mar 17, 2023
5ec3974
updated solution times.
discocube Mar 17, 2023
eeb9f76
updated solution times.
discocube Mar 17, 2023
7cb0bd5
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
2df64ec
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
febbfbe
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
790be8a
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
96d3567
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
a4a58df
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
8356f4f
removed last remaining while-loop for even less complexity.
discocube Mar 18, 2023
6c08eca
get_next refactored away redundant expression.
discocube Mar 18, 2023
89ad4c3
get_next refactored away redundant expression.
discocube Mar 18, 2023
1081594
get_next refactored away redundant expression.
discocube Mar 18, 2023
b305f2a
get_next refactored away redundant expression.
discocube Mar 18, 2023
353a285
get_next refactored away redundant expression.
discocube Mar 18, 2023
566bea2
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
199329b
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
8696529
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
2cfd817
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
324c0a3
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
1cfaa11
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
801e1c7
removed edges_adjacency_map in lieu of producing the adjacent edges o…
discocube Mar 18, 2023
608812e
ported to new data structure, indexmap, but is significantly slower, …
discocube Mar 19, 2023
03d9d7e
ported to new data structure, indexmap, but is significantly slower, …
discocube Mar 19, 2023
168d259
MOVED BACK TO THE OLD. INDEXMAP MADE IT SLOWER SOMEHOW.
discocube Mar 19, 2023
617c3dd
MOVED BACK TO THE OLD. INDEXMAP MADE IT SLOWER SOMEHOW.
discocube Mar 19, 2023
8d4098c
MOVED BACK TO THE OLD. INDEXMAP MADE IT SLOWER SOMEHOW.
discocube Mar 19, 2023
6d969b4
Pushing version using a mix of adj and vertices: Vec<((i16, i16, i16)…
discocube Mar 19, 2023
f92096c
reverted to previous version.
discocube Mar 19, 2023
aee82d5
reverted to previous version.
discocube Mar 19, 2023
44fec89
reverted to previous version.
discocube Mar 19, 2023
0f1b4fb
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
3ddc2c0
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
fbdb4f0
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
1c52530
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
4453930
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
9345883
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
e9c92f2
Converted cycle into a weaver class, and kept the other objects to th…
discocube Mar 20, 2023
a014e48
less is now more where more was once more than less.
discocube Mar 20, 2023
2236788
less is now more where more was once more than less.
discocube Mar 20, 2023
be4470b
less is now more where more was once more than less.
discocube Mar 20, 2023
729c57e
last update was an attempt at allocating resources before the functio…
discocube Mar 20, 2023
ba9bc18
last update was an attempt at allocating resources before the functio…
discocube Mar 20, 2023
4bc76b3
last update was an attempt at allocating resources before the functio…
discocube Mar 20, 2023
82c5bf3
last update was an attempt at allocating resources before the functio…
discocube Mar 20, 2023
ea6b357
last update was an attempt at allocating resources before the functio…
discocube Mar 20, 2023
9096257
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
4d7a20c
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
aea5db0
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
5c6339a
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
3142e77
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
37caf0c
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
7910c79
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
c2fa645
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
6a9d456
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
d978c54
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
206a131
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
e75cb4a
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
fc80eb1
current refactoring is best so far... re: memory. keep it up!
discocube Mar 21, 2023
f0bde42
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
ae115e8
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
bfeb80e
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
de26467
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
bcbc436
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
70593f3
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
b9e8817
current refactoring is best so far... re: memory. keep it up!
discocube Mar 22, 2023
e135b56
cleanup and writing with more intention.
discocube Mar 22, 2023
288ccbf
cleanup and writing with more intention.
discocube Mar 22, 2023
b9c4d5a
cleanup and writing with more intention.
discocube Mar 22, 2023
7de5af6
cleanup and writing with more intention.
discocube Mar 22, 2023
a35a8b2
cleanup and writing with more intention.
discocube Mar 22, 2023
6ea3ebb
cleanup and writing with more intention.
discocube Mar 22, 2023
289c078
cleanup and writing with more intention.
discocube Mar 22, 2023
2935da4
cleanup and writing with more intention.
discocube Mar 22, 2023
696ec6d
cleanup and writing with more intention.
discocube Mar 22, 2023
ae23d4e
cleanup and writing with more intention.
discocube Mar 22, 2023
b5cbd18
cleanup and writing with more intention.
discocube Mar 22, 2023
ad4f88f
cleanup and writing with more intention.
discocube Mar 22, 2023
b1e9bba
cleanup and writing with more intention.
discocube Mar 22, 2023
8a9f368
cleanup and writing with more intention.
discocube Mar 22, 2023
f03b8c7
cleanup and writing with more intention.
discocube Mar 22, 2023
917fce8
cleanup and writing with more intention.
discocube Mar 22, 2023
0c2261f
cleanup and writing with more intention.
discocube Mar 22, 2023
ca5ab23
cleanup and writing with more intention.
discocube Mar 22, 2023
4ed18cc
cleanup and writing with more intention.
discocube Mar 22, 2023
ab2e1f1
cleanup
discocube Mar 22, 2023
919cc49
cleanup
discocube Mar 22, 2023
d6b631c
cleanup
discocube Mar 22, 2023
aac4e6a
ditto...
discocube Mar 22, 2023
aa0341c
more cleanup
discocube Mar 22, 2023
5d189ed
cleanup
discocube Mar 22, 2023
12b5f0f
almost there...
discocube Mar 22, 2023
454acd9
making smaller
discocube Mar 22, 2023
de5b137
cleanup
discocube Mar 22, 2023
65fe10f
cleanup
discocube Mar 22, 2023
6f7e322
cleanup
discocube Mar 22, 2023
eba5392
cleaning
discocube Mar 22, 2023
d670625
cleaner
discocube Mar 22, 2023
d88b12b
clean
discocube Mar 22, 2023
44ccea8
clean
discocube Mar 22, 2023
ab4cddf
edited Readme
discocube Mar 23, 2023
19f9004
readme
discocube Mar 23, 2023
d5e3a16
The worst may happen if the student embarks upon computations or cons…
discocube Mar 23, 2023
b3c5709
Oh the pain!
discocube Mar 23, 2023
9428bc3
look for the pattern.
discocube Mar 23, 2023
346b511
fix another bad assumption regarding complexity of vec.contains(item).
discocube Mar 23, 2023
4233699
fix bad assumption
discocube Mar 23, 2023
83a9fc7
cleanup from refactor..
discocube Mar 23, 2023
b5ea6fe
gonna move onto vectorizing it all...
discocube Mar 23, 2023
ae8e5f4
added new results
discocube Mar 23, 2023
6d0af7e
new vec style
discocube Mar 23, 2023
f7243a7
new vec style
discocube Mar 23, 2023
f97a5e5
faster graph make, only what's needed for solving.
discocube Mar 24, 2023
6d28c0a
faster graph make, only what's needed for solving.
discocube Mar 24, 2023
9d98e9d
cleanup
discocube Mar 24, 2023
f66f81c
cleanup
discocube Mar 24, 2023
1484bee
cleanup
discocube Mar 24, 2023
90b0124
cleanup
discocube Mar 24, 2023
fc33e0b
reaching the billion mark!
discocube Mar 24, 2023
669e432
reaching the billion mark!
discocube Mar 24, 2023
86c33f9
reached a billion.
discocube Mar 24, 2023
7bdd5e9
reached a billion.
discocube Mar 24, 2023
9cc8ede
billion.
discocube Mar 24, 2023
3f3d112
billion.
discocube Mar 24, 2023
66ef039
cleanup
discocube Mar 24, 2023
0ff2d87
cleanup
discocube Mar 24, 2023
cf4189b
over 1.3 billion vertices in the graph.
discocube Mar 24, 2023
a4f2402
over 1.3 billion vertices in the graph.
discocube Mar 24, 2023
25a7ce8
1.373 billion.
discocube Mar 24, 2023
5d95e57
1.373 billion.
discocube Mar 24, 2023
c97222d
1.373 billion node graph.
discocube Mar 24, 2023
19f6623
1.373 billion node graph.
discocube Mar 24, 2023
0dfad39
1.373 billion node graph solved.
discocube Mar 24, 2023
bda5a5d
1.373 billion node graph solved.
discocube Mar 24, 2023
7baba23
1.373 billion node graph solved
discocube Mar 24, 2023
a9154c5
1.373 billion node graph solved
discocube Mar 24, 2023
09ce199
cleanup
discocube Mar 24, 2023
bd67bb3
cleanup
discocube Mar 24, 2023
32b7572
The only way to go fast is well.
discocube Mar 24, 2023
77f8cde
The only way to go fast is well.
discocube Mar 24, 2023
dd89b72
The only way to go fast is well.
discocube Mar 24, 2023
91acaf6
The only way to go fast is well.
discocube Mar 24, 2023
e3384f9
The only way to go fast is well.
discocube Mar 24, 2023
5e223dd
The only way to go fast is well.
discocube Mar 24, 2023
4cc5752
Patience is always easier to appreciate later.
discocube Mar 24, 2023
ec3097a
Patience is always easier to appreciate later.
discocube Mar 24, 2023
777de45
cleanup
discocube Mar 24, 2023
bc8b12a
cleanup
discocube Mar 24, 2023
fe472ba
clean clean
discocube Mar 24, 2023
8c6027f
clean clean
discocube Mar 24, 2023
9f2f7e3
1.373 billion node graph solved.
discocube Mar 24, 2023
af03493
1.373 billion node graph solved.
discocube Mar 24, 2023
893d7fb
cleanup
discocube Mar 24, 2023
e72968f
cleanup
discocube Mar 24, 2023
87859a3
clean
discocube Mar 24, 2023
005fa9e
clean
discocube Mar 24, 2023
dfaca9e
1.373 billion node graph solved.
discocube Mar 24, 2023
93abc5f
1.373 billion node graph solved.
discocube Mar 24, 2023
6d83201
keep on going no stop no.
discocube Mar 24, 2023
7c270f6
keep on going no stop no.
discocube Mar 24, 2023
1cd5a64
1.373 billion node graph solved.
discocube Mar 24, 2023
808f811
1.373 billion node graph solved.
discocube Mar 24, 2023
9efb5b3
clean
discocube Mar 24, 2023
e8656e4
clean
discocube Mar 24, 2023
4c97400
rename
discocube Mar 24, 2023
7d141d3
rename
discocube Mar 24, 2023
bc55dde
maybe 8 billion node graph? A node for every body.
discocube Mar 24, 2023
e160c7c
maybe 8 billion node graph? A node for every body.
discocube Mar 24, 2023
de25a21
keep on going.
discocube Mar 24, 2023
0c912b5
keep on going.
discocube Mar 24, 2023
204b099
...
discocube Mar 24, 2023
70daffb
...
discocube Mar 24, 2023
6310979
...
discocube Mar 25, 2023
3714703
...
discocube Mar 25, 2023
9c90dd8
...
discocube Mar 25, 2023
2cbc36e
...
discocube Mar 25, 2023
e63173e
| 🇳 1000 | ⭕️1_337_336_000 |
discocube Mar 25, 2023
141fe40
| 🇳 1000 | ⭕️1_337_336_000 |
discocube Mar 25, 2023
f4e2f77
| 🇳 1000 | ⭕️1_337_336_000 |
discocube Mar 25, 2023
e18c360
| 🇳 1000 | ⭕️1_337_336_000 |
discocube Mar 25, 2023
155fff6
...
discocube Mar 25, 2023
3be1712
...
discocube Mar 25, 2023
bdcf48c
Only way to go fast is well.
discocube Mar 25, 2023
2d41e95
Only way to go fast is well.
discocube Mar 25, 2023
17dad43
The only way to go fast is well.
discocube Mar 25, 2023
0d3b49e
The only way to go fast is well.
discocube Mar 25, 2023
1d61b78
more cleanup
discocube Mar 25, 2023
764850c
more cleanup
discocube Mar 25, 2023
bbfa6f4
over a billion.
discocube Mar 25, 2023
013877f
over a billion.
discocube Mar 25, 2023
4af4470
8 billion?
discocube Mar 25, 2023
0af1e8c
8 billion?
discocube Mar 25, 2023
90c99eb
cleanup update timelist.
discocube Mar 25, 2023
f4aa204
cleanup update timelist.
discocube Mar 25, 2023
89c51c6
up
discocube Mar 26, 2023
2dbb4e1
up
discocube Mar 26, 2023
ecceda4
up
discocube Mar 26, 2023
6bcacc7
p
discocube Mar 26, 2023
ce48c4b
clean
discocube Mar 27, 2023
40a14d5
c
discocube Mar 27, 2023
2ca4ead
Merge branch 'master' of https://github.com/discocube/easy_dc_rust_vec
discocube Mar 27, 2023
03b6e64
after move in old repo
discocube Mar 27, 2023
127c0fc
fixed
discocube Mar 27, 2023
ae7f9e2
use plot_solution to visual results from weave.
discocube Mar 28, 2023
b7550cc
Merge branch 'master' of https://github.com/discocube/weave
discocube Mar 28, 2023
a8745d9
Update README.md
discocube Mar 30, 2023
7dd4d6f
Update Cargo.toml
discocube Mar 30, 2023
53e2340
Update main.rs
discocube Mar 30, 2023
b8e1154
Update weave.rs
discocube Mar 30, 2023
31b2c8f
Update utils.rs
discocube Mar 30, 2023
9884da0
Update defs.rs
discocube Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/target
/src/attempts/
/src/ignoreme/
/src/aplay/
/.vscode
/.idea/
/.idea/misc.xml
/src/erroring.rs
/src/versions.rs
/timing_order.txt
/oprofile_data
/oprofile_data
96 changes: 96 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ version = "0.1.0"
edition = "2021"

[dependencies]
chrono = "0.4.24"
common_macros = "0.1.1"
csv = "1.2.1"
itertools = "0.10.5"
ndarray = "0.15.6"
ndarray = { version = "0.15.6", features = ["blas", "rayon", "matrixmultiply-threading"] }
rayon = "1.7.0"
serde = { version = "1", features = ["derive"] }

[profile.release]
debug = true
Expand Down
1,686 changes: 930 additions & 756 deletions README.md

Large diffs are not rendered by default.

Binary file added imgs/8_to_212million.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed imgs/8_to_68085920.png
Binary file not shown.
Binary file added imgs/hauy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imgs/hauyCabinett.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/icosian.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 90 additions & 62 deletions src/graph/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,80 @@ use std::collections::{HashMap, HashSet, VecDeque};

use super::utils::{check_edge::is_valid_edge, modify::orient};

pub const DISP_VECTORS: [[[i16; 2]; 2]; 4] = [
[[-2, 0], [0, -2]],
[[-2, 0], [0, 2]],
[[2, 0], [0, 2]],
[[2, 0], [0, -2]],
];

pub type Adjacency = HashMap<Node, Neighbors>;
pub type ZAdjacency = HashMap<[Point; 2], Vec<[Point; 2]>>;
pub type Bobbins = Vec<Node>;
pub type Count = usize;
pub type Edge = (Node, Node);
pub type Edges = HashSet<Edge>;
pub type Loom = Vec<YarnEnds>;
pub type Neighbors = HashSet<Node>;
pub type Node = u32;
pub type Loom = Vec<VecDeque<[i16; 3]>>;
pub type LoomSlice = [VecDeque<[i16; 3]>];
pub type Neighbors = HashSet<[i16; 3]>;
pub type Node = [i16; 3];
pub type Nodes = HashSet<Node>;
pub type Order = u32;
pub type Point = i16;
pub type Points = HashSet<Point>;
pub type Solution = Tour;
pub type Spindle = Vec<[i16; 2]>;
pub type Spool = HashMap<u32, Yarn>;
pub type Spun = HashMap<[i16; 2], bool>;
pub type Subtours = Vec<Tour>;
pub type Tour = Vec<Node>;
pub type TourSlice<'a> = &'a [Node];
pub type TourSliceThick<'a> = &'a [[i16; 2]];
pub type Tour = Vec<[i16; 3]>;
pub type TourSlice<'a> = &'a [[i16; 2]];
pub type YarnEnds = VecDeque<Node>;
pub type Var2 = [i16; 2];
pub type Vert = (Point, Point, Point);
pub type Verts = [Vert];
pub type Verts = [[i16; 3]];
pub type VecVert = Vec<Vert>;
pub type VIMap = HashMap<Vert, Node>;
pub type Warps = Subtours;
pub type Warps = Vec<Vec<[i16; 3]>>;
pub type Weights = HashMap<Node, Point>;
pub type SignedIdx = i32;
pub type Yarn = Array2<Point>;
pub type ZlevelNodesMap = HashMap<Point, Nodes>;
pub type ZOrder = Vec<(Point, usize)>;
use serde::Serialize;
use std::error::Error;

#[derive(Debug, Clone, Copy)]
pub enum XY {
X,
Y,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
struct Vector {
x: i16,
y: i16,
z: i16,
}

#[derive(Clone, Debug)]
pub struct Weaver<'a> {
pub struct Weaver {
pub data: Tour,
verts: &'a Verts,
lead: bool,
min_xyz: Point,
order: u32,
}

impl<'a> Weaver<'a> {
pub fn new(
mut data: YarnEnds,
verts: &'a Verts,
lead: bool,
min_xyz: Point,
) -> Weaver<'a> {
impl Weaver {
pub fn new(mut data: YarnEnds, lead: bool, min_xyz: Point, order: u32) -> Weaver {
let mut preallocated = Vec::with_capacity(order as usize);
preallocated.extend(data.drain(..));
Weaver {
data: data.drain(..).collect(),
verts,
data: preallocated,
lead,
min_xyz,
order: verts.len() as u32,
order,
}
}

Expand All @@ -65,28 +86,19 @@ impl<'a> Weaver<'a> {
.iter()
.circular_tuple_windows()
.map(|(a, b)| orient(*a, *b))
.filter(|&(m, n)| {
is_valid_edge(
self.verts[m as usize],
self.verts[n as usize],
self.min_xyz,
self.order,
false,
)
})
.filter(|&(m, n)| is_valid_edge(m, n, self.min_xyz, self.order, false))
.collect()
}

pub fn join(&mut self, edge: Edge, wedge: Edge, warp: &mut Tour) {
self.rotated_to_edge(edge);
Weaver::rotate_to_edge(warp, wedge);
self.data.append(warp);
}

pub fn rotated_to_edge(&mut self, (lhs, rhs): (u32, u32)) {
pub fn rotated_to_edge(&mut self, (lhs, rhs): ([i16; 3], [i16; 3])) {
// more prudent than using splice() which has preferences for optimality:
// The tail (elements in the vector after range) is empty,
// or replace_with yields fewer or equal elements than range’s length
// or the lower bound of its size_hint() is exact. blah blah blah.
// More steps to fulfill optimality than just doing what's correct.
if lhs == self.data[self.data.len() - 1] && rhs == self.data[0] {
self.data.reverse();
} else {
} else if !(lhs == self.data[0] && rhs == self.data[self.data.len() - 1]) {
match (
self.data.iter().position(|&x| x == lhs).unwrap(),
self.data.iter().position(|&x| x == rhs).unwrap(),
Expand All @@ -100,19 +112,19 @@ impl<'a> Weaver<'a> {
}
}

pub fn rotate_to_edge(other: &mut Tour, (lhs, rhs): (u32, u32)) {
if lhs == other[other.len() - 1] && rhs == other[0] {
other.reverse();
} else {
pub fn rotate_to_edge(cycle: &mut Tour, (lhs, rhs): ([i16; 3], [i16; 3])) {
if lhs == cycle[cycle.len() - 1] && rhs == cycle[0] {
cycle.reverse();
} else if !(lhs == cycle[0] && rhs == cycle[cycle.len() - 1]) {
match (
other.iter().position(|&x| x == lhs).unwrap(),
other.iter().position(|&x| x == rhs).unwrap(),
cycle.iter().position(|&x| x == lhs).unwrap(),
cycle.iter().position(|&x| x == rhs).unwrap(),
) {
(idx_lhs, idx_rhs) if idx_lhs < idx_rhs => {
other.rotate_left(idx_rhs);
other.reverse()
cycle.rotate_left(idx_rhs);
cycle.reverse()
}
(idx_lhs, _) => other.rotate_left(idx_lhs),
(idx_lhs, _) => cycle.rotate_left(idx_lhs),
}
}
}
Expand All @@ -122,27 +134,43 @@ impl<'a> Weaver<'a> {
.iter()
.circular_tuple_windows()
.map(|(a, b)| orient(*a, *b))
.filter(|&(m, n)| {
is_valid_edge(
self.verts[m as usize],
self.verts[n as usize],
self.min_xyz,
self.order,
self.lead,
)
})
.filter(|&(m, n)| is_valid_edge(m, n, self.min_xyz, self.order, self.lead))
.collect()
}

pub fn get_nodes(&self) -> Solution {
pub fn get_weave(&self) -> Solution {
self.data.to_vec()
}

pub fn get_vectors(&self) -> VecVert {
self.data
.to_vec()
.iter()
.map(|node| self.verts[*node as usize])
.collect()
/// Python script using plotly and pandas to display the solution from the .csv file produced by the function below:
///```
/// import pandas as pd
/// import plotly.express as px
///
/// def create_3d_line_plot(file_path):
/// df = pd.read_csv(file_path)
/// fig = px.line_3d(df, x='X', y='Y', z='Z')
/// fig.show()
///
///```
/// Save solution to file_path as a csv file where each axis X, Y, Z is a separate column.
/// Structured for easy read and plotting using python and plotly (see above).
pub fn save_to_csv(&self, file_path: &str) -> Result<(), Box<dyn Error>> {
let file = std::fs::File::create(file_path)?;
let mut writer = csv::Writer::from_writer(file);
self.data.iter().for_each(|[x, y, z]| {
writer
.serialize(Vector {
x: *x,
y: *y,
z: *z,
})
.ok();
});
// Add first value to last to form a loop:
let [x, y, z] = self.data[0];
writer.serialize(Vector { x, y, z })?;
writer.flush()?;
Ok(())
}
}
Loading