-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39f22c9
commit 5c704bb
Showing
12 changed files
with
145 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
HarmonyDB.Index/HarmonyDB.Index.Analysis/Models/Index/Blocks/EdgeBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using HarmonyDB.Index.Analysis.Models.Index.Blocks.Interfaces; | ||
using HarmonyDB.Index.Analysis.Models.Index.Enums; | ||
|
||
namespace HarmonyDB.Index.Analysis.Models.Index.Blocks; | ||
|
||
public class EdgeBlock(IndexedBlockType type) : IIndexedBlock | ||
{ | ||
public string Normalized => throw new InvalidOperationException(); | ||
|
||
public byte NormalizationRoot => throw new InvalidOperationException(); | ||
|
||
public int StartIndex => throw new InvalidOperationException(); | ||
|
||
public int EndIndex => throw new InvalidOperationException(); | ||
|
||
public int BlockLength => 0; | ||
|
||
public IEnumerable<IIndexedBlock> Children => []; | ||
|
||
public string? GetNormalizedCoordinate(int index) => null; // song start blocks do not have normalization shifts | ||
|
||
public IndexedBlockType Type { get; } = type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ public enum IndexedBlockType : byte | |
Sequence, | ||
PolyLoop, | ||
PingPong, | ||
SequenceStart, | ||
SequenceEnd, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
HarmonyDB.Index/HarmonyDB.Index.Analysis/Services/Dijkstra.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using HarmonyDB.Index.Analysis.Models.Index.Blocks.Interfaces; | ||
using HarmonyDB.Index.Analysis.Models.Index.Enums; | ||
using HarmonyDB.Index.Analysis.Models.Index.Graphs; | ||
|
||
namespace HarmonyDB.Index.Analysis.Services; | ||
|
||
public class Dijkstra | ||
{ | ||
public List<IIndexedBlock>? GetShortestPath(BlockGraph graph) | ||
{ | ||
var startBlock = graph.Environments.Single(x => x.Block.Type == IndexedBlockType.SequenceStart).Block; // Assuming the start is the first block in environments | ||
var targetBlock = graph.Environments.Single(x => x.Block.Type == IndexedBlockType.SequenceEnd).Block; // Assuming the target is the last block in environments | ||
|
||
var distances = new Dictionary<IIndexedBlock, float>(); | ||
var previousBlocks = new Dictionary<IIndexedBlock, IIndexedBlock?>(); | ||
var allBlocks = graph.Environments.Select(env => env.Block).Distinct().ToList(); | ||
|
||
foreach (var block in allBlocks) | ||
{ | ||
distances[block] = float.MaxValue; // Initialize all distances to infinity | ||
previousBlocks[block] = null; // Initialize all previous blocks to null | ||
} | ||
|
||
distances[startBlock] = 0; // Distance to start block is 0 | ||
|
||
var priorityQueue = new PriorityQueue<IIndexedBlock, float>(); | ||
priorityQueue.Enqueue(startBlock, 0); | ||
|
||
while (priorityQueue.Count != 0) | ||
{ | ||
var currentBlock = priorityQueue.Dequeue(); | ||
|
||
if (currentBlock == targetBlock) | ||
break; | ||
|
||
var currentEnvironment = graph.EnvironmentsByBlock[currentBlock]; | ||
var neighbors = currentEnvironment.LeftJoints.Select(joint => joint.Block2.Block) | ||
.Concat(currentEnvironment.RightJoints.Select(joint => joint.Block2.Block)) | ||
.Distinct(); | ||
|
||
foreach (var neighbor in neighbors) | ||
{ | ||
var alt = distances[currentBlock] + neighbor.Score; | ||
if (alt < distances[neighbor]) | ||
{ | ||
distances[neighbor] = alt; | ||
previousBlocks[neighbor] = currentBlock; | ||
priorityQueue.Enqueue(neighbor, alt); | ||
} | ||
} | ||
} | ||
|
||
return ReconstructPath(previousBlocks, startBlock, targetBlock); | ||
} | ||
|
||
private List<IIndexedBlock>? ReconstructPath(Dictionary<IIndexedBlock, IIndexedBlock?> previousBlocks, IIndexedBlock startBlock, IIndexedBlock targetBlock) | ||
{ | ||
var path = new List<IIndexedBlock>(); | ||
for (var at = targetBlock; at != null; at = previousBlocks[at]) | ||
{ | ||
path.Add(at); | ||
} | ||
path.Reverse(); | ||
return path.Contains(startBlock) ? path : null; // Return the path if it includes the start block, otherwise return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
HarmonyDB.Index/HarmonyDB.Index.Analysis/Services/ProgressionsOptimizer.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters