Skip to content

Commit

Permalink
Sample data button for TSP added
Browse files Browse the repository at this point in the history
  • Loading branch information
enviGit committed Nov 9, 2024
1 parent a80c8f9 commit c9083e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions OptimizationIssues/Views/TSPView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Button x:Name="SolveButton" Content="Rozwiąż problem" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Click="SolveButton_Click"/>
</StackPanel>
<StackPanel Grid.Column="1" Margin="10">
<Button Content="Generuj przykładowe dane" VerticalAlignment="Top" Width="200" Click="GenerateSampleDataButton_Click"/>
<TextBlock Text="Wyniki:" FontWeight="Bold" FontSize="16" VerticalAlignment="Top"/>
<TextBlock x:Name="ResultTextBlock" Text="Tutaj pojawią się wyniki..." VerticalAlignment="Top" FontSize="14"/>
</StackPanel>
Expand Down
42 changes: 42 additions & 0 deletions OptimizationIssues/Views/TSPView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS8629
using OptimizationIssues.ViewModels;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
Expand Down Expand Up @@ -149,5 +150,46 @@ private void InputsChanged(object sender, TextChangedEventArgs e)
{
SolveButton.IsEnabled = ValidateInputs(out _, out _);
}

private void GenerateSampleDataButton_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();

int numberOfCities = rand.Next(3, 11);
NumberOfCitiesTextBox.Text = numberOfCities.ToString();

var distanceMatrix = GenerateRandomDistanceMatrix(numberOfCities);
DistanceMatrixTextBox.Text = FormatDistanceMatrix(distanceMatrix);

SolveButton.IsEnabled = true;
}

private List<List<int>> GenerateRandomDistanceMatrix(int size)
{
Random rand = new Random();
var matrix = new List<List<int>>();

for (int i = 0; i < size; i++)
{
var row = new List<int>();

for (int j = 0; j < size; j++)
row.Add(i == j ? 0 : rand.Next(10, 101));

matrix.Add(row);
}

return matrix;
}

private string FormatDistanceMatrix(List<List<int>> matrix)
{
var result = new StringBuilder();

foreach (var row in matrix)
result.AppendLine(string.Join(",", row));

return result.ToString();
}
}
}

0 comments on commit c9083e2

Please sign in to comment.