Skip to content

Commit

Permalink
Moved combinations founder into main methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Sep 17, 2022
1 parent c67fb1c commit b5d3340
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
23 changes: 1 addition & 22 deletions FloatTool/Common/Calculations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,7 @@ public static bool NextCombination(int[] num, int n)
}
return false;
}

public static IEnumerable<InputSkin[]> Combinations(InputSkin[] elem, int start, int skip)
{
int size = elem.Length - 10;
int[] numbers = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
InputSkin[] resultList = new InputSkin[10];
bool running = true;

for (int i = 0; i < start; i++)
running = NextCombination(numbers, size);

while (running)
{
for (int i = 0; i < 10; ++i)
resultList[i] = elem[numbers[i]];
yield return resultList;

for (int i = 0; i < skip; i++)
running = NextCombination(numbers, size);
}
}


public static long GetCombinationsCount(int poolSize)
{
BigInteger fact1 = poolSize;
Expand Down
20 changes: 19 additions & 1 deletion FloatTool/Views/BenchmarkWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,21 @@ private void PublishResult_Click(object sender, RoutedEventArgs e)

private static void FloatCraftWorkerThread(CraftSearchSetup options)
{
foreach (InputSkin[] resultList in Calculations.Combinations(options.SkinPool, options.ThreadID, options.ThreadCount))
int size = options.SkinPool.Length - 10;
int[] numbers = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
InputSkin[] resultList = new InputSkin[10];
bool running = true;

for (int i = 0; i < options.ThreadID; i++)
running = Calculations.NextCombination(numbers, size);

while (running)
{
for (int i = 0; i < 10; ++i)
resultList[i] = options.SkinPool[numbers[i]];

// Check if the combination is valid

for (int i = 0; i < options.Outcomes.Length; ++i)
{
double resultFloat = Calculations.Craft(
Expand Down Expand Up @@ -115,7 +128,12 @@ private static void FloatCraftWorkerThread(CraftSearchSetup options)
}

Interlocked.Increment(ref PassedCombinations);

// Get next combination
for (int i = 0; i < options.ThreadCount; i++)
running = Calculations.NextCombination(numbers, size);
}

}

private void StartBenchmark_Click(object sender, RoutedEventArgs e)
Expand Down
20 changes: 19 additions & 1 deletion FloatTool/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,21 @@ private void SetStatus(string stringCode)

private void FloatCraftWorkerThread(CraftSearchSetup options)
{
foreach (InputSkin[] resultList in Calculations.Combinations(options.SkinPool, options.ThreadID, options.ThreadCount))
int size = options.SkinPool.Length - 10;
int[] numbers = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
InputSkin[] resultList = new InputSkin[10];
bool running = true;

for (int i = 0; i < options.ThreadID; i++)
running = Calculations.NextCombination(numbers, size);

while (running)
{
for (int i = 0; i < 10; ++i)
resultList[i] = options.SkinPool[numbers[i]];

// Check if the combination is valid

for (int i = 0; i < options.Outcomes.Length; ++i)
{
double resultFloat = Calculations.Craft(
Expand Down Expand Up @@ -249,6 +262,11 @@ private void FloatCraftWorkerThread(CraftSearchSetup options)

if (CancellationToken.IsCancellationRequested)
break;

// Get next combination

for (int i = 0; i < options.ThreadCount; i++)
running = Calculations.NextCombination(numbers, size);
}
}

Expand Down

0 comments on commit b5d3340

Please sign in to comment.