Skip to content

Commit 8c1c71a

Browse files
committed
Merge branch 'dev'
2 parents a542ebf + dd758f8 commit 8c1c71a

File tree

14 files changed

+565
-64
lines changed

14 files changed

+565
-64
lines changed

.github/workflows/publish.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ jobs:
110110
# --- NuGet Common Package Build/Publish ---
111111
- name: Build PSGraph.Common (Debug on prerelease, Release on release)
112112
run: |
113-
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
114-
dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Debug --no-restore
113+
if [ -n "${{ steps.set_version.outputs.prerelease }}" ]; then
114+
VERSION="${{ steps.set_version.outputs.version }}-${{ steps.set_version.outputs.prerelease }}"
115+
CONFIG=Debug
115116
else
116-
dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Release --no-restore
117+
VERSION="${{ steps.set_version.outputs.version }}"
118+
CONFIG=Release
117119
fi
120+
dotnet build PSGraph.Common/PSGraph.Common.csproj \
121+
--configuration $CONFIG \
122+
--no-restore \
123+
-p:PackageVersion="$VERSION" \
124+
-p:Version="$VERSION"
118125
119126
- name: Pack PSGraph.Common (Debug/pre-release on prerelease, Release on release)
120127
shell: bash
@@ -130,7 +137,8 @@ jobs:
130137
--configuration $CONFIG \
131138
--no-build \
132139
--output ./nupkg \
133-
/p:PackageVersion="$VERSION"
140+
-p:PackageVersion="$VERSION" \
141+
-p:Version="$VERSION"
134142
135143
- name: Publish PSGraph.Common to NuGet
136144
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

PSGraph.Common/Interface/IDsmView.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace PSGraph.DesignStructureMatrix
55
public interface IDsmView
66
{
77
public abstract SvgDocument ToSvg();
8+
public abstract string ToSvgString();
89
public abstract void ExportText(string Path);
10+
public abstract string ExportText();
11+
public abstract string ToVegaSpec(VegaExportTypes exportType, string modulePath);
912
public string ExportGraphViz();
1013
}
1114
}

PSGraph.Common/Model/DSMExportTypes.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
{
33
public enum DSMExportTypes
44
{
5-
SVG,
6-
TEXT
5+
//TODO: replaced with Vega as visual was really bad. perhaps need to rewrite it
6+
//SVG,
7+
TEXT,
8+
VEGA_JSON,
9+
VEGA_HTML
710
}
811
}

PSGraph.Common/PSGraph.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<VersionPrefix>1.0.3</VersionPrefix>
7+
<VersionPrefix>2.3.3</VersionPrefix>
88
<Authors>Andrey Vernigora</Authors>
99
<PackageId>PSGraph.Common</PackageId>
1010
<Description>Common types of PSGraph module</Description>

PSGraph.Tests/DsmPartitioningTests.cs

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,59 @@ namespace PSGraph.Tests
88
{
99
public class DsmPartitioningTests
1010
{
11+
12+
private Matrix<float> ReorderMatrix(Matrix<float> original, Dictionary<PSVertex, int> actualIndex, string[] expectedOrder)
13+
{
14+
int size = expectedOrder.Length;
15+
var reordered = Matrix<float>.Build.Dense(size, size);
16+
17+
for (int i = 0; i < size; i++)
18+
{
19+
var rowVertex = new PSVertex(expectedOrder[i]);
20+
int sourceRow = actualIndex[rowVertex];
21+
22+
for (int j = 0; j < size; j++)
23+
{
24+
var colVertex = new PSVertex(expectedOrder[j]);
25+
int sourceCol = actualIndex[colVertex];
26+
27+
reordered[i, j] = original[sourceRow, sourceCol];
28+
}
29+
}
30+
31+
return reordered;
32+
}
33+
34+
private void AssertVertexGroupsAreClustered(Dictionary<PSVertex, int> rowIndex, List<List<PSVertex>> expectedGroups)
35+
{
36+
var allIndices = new Dictionary<string, int>();
37+
foreach (var kvp in rowIndex)
38+
allIndices[kvp.Key.Name] = kvp.Value;
39+
40+
for (int groupIdx = 0; groupIdx < expectedGroups.Count; groupIdx++)
41+
{
42+
var group = expectedGroups[groupIdx];
43+
var indices = group.Select(v => allIndices[v.Label]).OrderBy(i => i).ToList();
44+
45+
// Все индексы должны быть рядом
46+
for (int i = 1; i < indices.Count; i++)
47+
{
48+
(indices[i] - indices[i - 1]).Should().BeLessThanOrEqualTo(1,
49+
$"vertices in group {groupIdx} ({string.Join(",", group)}) should be adjacent");
50+
}
51+
52+
// Между группами индексы должны быть дальше
53+
for (int j = groupIdx + 1; j < expectedGroups.Count; j++)
54+
{
55+
var otherGroup = expectedGroups[j];
56+
var otherIndices = otherGroup.Select(v => allIndices[v.Label]).OrderBy(i => i).ToList();
57+
58+
indices.Last().Should().BeLessThan(otherIndices.First(),
59+
$"group {groupIdx} should come before group {j}");
60+
}
61+
}
62+
}
63+
1164
[Fact]
1265
public void BasicPartitioning_ShouldPartitionCorrectly()
1366
{
@@ -16,11 +69,12 @@ public void BasicPartitioning_ShouldPartitionCorrectly()
1669

1770
var algo = new DsmClassicPartitioningAlgorithm(dsm);
1871
var result = algo.Partition();
19-
72+
2073
result.Should().NotBeNull("Partitioning result should not be null");
21-
74+
75+
2276
// Expected DSM after partitioning
23-
float[,] expectedMatrix = {
77+
float[,] expectedMatrix = {
2478
{ 0, 0, 0, 0, 0, 0, 0 },
2579
{ 0, 0, 0, 1, 0, 0, 0 },
2680
{ 0, 1, 0, 0, 0, 0, 0 },
@@ -30,25 +84,47 @@ public void BasicPartitioning_ShouldPartitionCorrectly()
3084
{ 1, 0, 0, 0, 0, 1, 0 }
3185
};
3286

87+
// Expected row/column order after partitioning
88+
string[] expectedOrder = { "F", "B", "D", "G", "A", "C", "E" };
89+
90+
// Задаем ожидаемые группы
91+
var expectedGroups = new List<List<PSVertex>>
92+
{
93+
new() { new PSVertex("F"), new PSVertex("E") },
94+
new() { new PSVertex("B"), new PSVertex("D"), new PSVertex("G") },
95+
new() { new PSVertex("A"), new PSVertex("C") }
96+
};
97+
98+
Console.WriteLine("Row indices:");
99+
foreach (var kvp in result.RowIndex.OrderBy(k => k.Value))
100+
{
101+
Console.WriteLine($"{kvp.Key.Name} => {kvp.Value}");
102+
}
103+
104+
// Проверим, что группы упорядочены и внутри сжаты
105+
AssertVertexGroupsAreClustered(result.RowIndex, expectedGroups);
106+
107+
var reorderedActual = ReorderMatrix(result.DsmMatrixView, result.RowIndex, expectedOrder);
108+
33109
// Create expected matrix using MathNet
34110
var targetMatrix = Matrix<Single>.Build.DenseOfArray(expectedMatrix);
35111

36112
// Check if the partitioned DSM matrix matches the expected matrix
37-
result.DsmMatrixView.Should().BeEquivalentTo(targetMatrix, "The partitioned DSM matrix should match the expected matrix");
113+
reorderedActual.Should().BeEquivalentTo(targetMatrix, "The partitioned DSM matrix should match the expected matrix");
38114

39-
// Expected row/column order after partitioning
40-
string[] expectedOrder = { "F", "B", "D", "G", "A", "C", "E" };
41115

42116
// Validate row and column indices match the expected vertex order
43117
for (int idx = 0; idx < expectedOrder.Length; idx++)
44118
{
45119
var vertex = new PSVertex(expectedOrder[idx]);
46120

47121
result.RowIndex.Should().ContainKey(vertex);
48-
result.RowIndex[vertex].Should().Be(idx, $"Row index for vertex {vertex.Name} should be {idx}");
49-
50122
result.ColIndex.Should().ContainKey(vertex);
51-
result.ColIndex[vertex].Should().Be(idx, $"Column index for vertex {vertex.Name} should be {idx}");
123+
}
124+
125+
for (int i = 0; i < reorderedActual.RowCount; i++)
126+
{
127+
reorderedActual[i, i].Should().Be(0, $"self-dependency at index {i} should be zero");
52128
}
53129
}
54130
}

PSGraph.Vega.Extensions/Assets/vega.adj.matrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://vega.github.io/schema/vega/v5.json",
3-
"description": "A re-orderable adjacency matrix depicting character co-occurrence in the novel Les Misérables.",
3+
"description": "A re-orderable adjacency matrix.",
44
"width": 1000,
55
"height": 1000,
66
"padding": 2,

0 commit comments

Comments
 (0)