Skip to content

Commit c9083e2

Browse files
committed
Sample data button for TSP added
1 parent a80c8f9 commit c9083e2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

OptimizationIssues/Views/TSPView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Button x:Name="SolveButton" Content="Rozwiąż problem" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Click="SolveButton_Click"/>
7272
</StackPanel>
7373
<StackPanel Grid.Column="1" Margin="10">
74+
<Button Content="Generuj przykładowe dane" VerticalAlignment="Top" Width="200" Click="GenerateSampleDataButton_Click"/>
7475
<TextBlock Text="Wyniki:" FontWeight="Bold" FontSize="16" VerticalAlignment="Top"/>
7576
<TextBlock x:Name="ResultTextBlock" Text="Tutaj pojawią się wyniki..." VerticalAlignment="Top" FontSize="14"/>
7677
</StackPanel>

OptimizationIssues/Views/TSPView.xaml.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma warning disable CS8629
22
using OptimizationIssues.ViewModels;
33
using System.Diagnostics;
4+
using System.Text;
45
using System.Windows;
56
using System.Windows.Controls;
67
using System.Windows.Documents;
@@ -149,5 +150,46 @@ private void InputsChanged(object sender, TextChangedEventArgs e)
149150
{
150151
SolveButton.IsEnabled = ValidateInputs(out _, out _);
151152
}
153+
154+
private void GenerateSampleDataButton_Click(object sender, RoutedEventArgs e)
155+
{
156+
Random rand = new Random();
157+
158+
int numberOfCities = rand.Next(3, 11);
159+
NumberOfCitiesTextBox.Text = numberOfCities.ToString();
160+
161+
var distanceMatrix = GenerateRandomDistanceMatrix(numberOfCities);
162+
DistanceMatrixTextBox.Text = FormatDistanceMatrix(distanceMatrix);
163+
164+
SolveButton.IsEnabled = true;
165+
}
166+
167+
private List<List<int>> GenerateRandomDistanceMatrix(int size)
168+
{
169+
Random rand = new Random();
170+
var matrix = new List<List<int>>();
171+
172+
for (int i = 0; i < size; i++)
173+
{
174+
var row = new List<int>();
175+
176+
for (int j = 0; j < size; j++)
177+
row.Add(i == j ? 0 : rand.Next(10, 101));
178+
179+
matrix.Add(row);
180+
}
181+
182+
return matrix;
183+
}
184+
185+
private string FormatDistanceMatrix(List<List<int>> matrix)
186+
{
187+
var result = new StringBuilder();
188+
189+
foreach (var row in matrix)
190+
result.AppendLine(string.Join(",", row));
191+
192+
return result.ToString();
193+
}
152194
}
153195
}

0 commit comments

Comments
 (0)