mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
More stringable removal for performance.
This commit is contained in:
@ -72,7 +72,7 @@ abstract class FactorGraphLayer
|
||||
*/
|
||||
protected function scheduleSequence(array $itemsToSequence, string $name): ScheduleSequence
|
||||
{
|
||||
return new ScheduleSequence($name, $itemsToSequence);
|
||||
return new ScheduleSequence($itemsToSequence);
|
||||
}
|
||||
|
||||
protected function addLayerFactor(Factor $factor): void
|
||||
|
@ -4,16 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
abstract class Schedule implements \Stringable
|
||||
abstract class Schedule
|
||||
{
|
||||
protected function __construct(private readonly string $name)
|
||||
{
|
||||
}
|
||||
|
||||
abstract public function visit(int $depth = -1, int $maxDepth = 0): float;
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,8 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleLoop extends Schedule
|
||||
{
|
||||
public function __construct(string $name, private readonly Schedule $scheduleToLoop, private readonly float $maxDelta)
|
||||
public function __construct(private readonly Schedule $scheduleToLoop, private readonly float $maxDelta)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function visit(int $depth = -1, int $maxDepth = 0): float
|
||||
|
@ -9,9 +9,8 @@ class ScheduleSequence extends Schedule
|
||||
/**
|
||||
* @param Schedule[] $schedules
|
||||
*/
|
||||
public function __construct(string $name, private readonly array $schedules)
|
||||
public function __construct(private readonly array $schedules)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function visit(int $depth = -1, int $maxDepth = 0): float
|
||||
|
@ -6,15 +6,12 @@ namespace DNW\Skills\FactorGraphs;
|
||||
|
||||
class ScheduleStep extends Schedule
|
||||
{
|
||||
public function __construct(string $name, private readonly Factor $factor, private readonly int $index)
|
||||
public function __construct(private readonly Factor $factor, private readonly int $index)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function visit(int $depth = -1, int $maxDepth = 0): float
|
||||
{
|
||||
$currentFactor = $this->factor;
|
||||
|
||||
return $currentFactor->updateMessageIndex($this->index);
|
||||
return $this->factor->updateMessageIndex($this->index);
|
||||
}
|
||||
}
|
||||
|
@ -63,17 +63,17 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$firstDifferencesFactor = $localFactors[0];
|
||||
$lastDifferencesFactor = $localFactors[$totalTeamDifferences - 1];
|
||||
|
||||
//inner schedule
|
||||
return new ScheduleSequence(
|
||||
'inner schedule',
|
||||
[
|
||||
$loop,
|
||||
//teamPerformanceToPerformanceDifferenceFactors[0] @ 1
|
||||
new ScheduleStep(
|
||||
'teamPerformanceToPerformanceDifferenceFactors[0] @ 1',
|
||||
$firstDifferencesFactor,
|
||||
1
|
||||
),
|
||||
//teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2
|
||||
new ScheduleStep(
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[teamTeamDifferences = %d - 1] @ 2', $totalTeamDifferences),
|
||||
$lastDifferencesFactor,
|
||||
2
|
||||
),
|
||||
@ -89,13 +89,13 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$firstPerfToTeamDiff = $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[0];
|
||||
$firstTeamDiffComparison = $teamDifferencesComparisonLayerLocalFactors[0];
|
||||
$itemsToSequence = [
|
||||
//send team perf to perf differences
|
||||
new ScheduleStep(
|
||||
'send team perf to perf differences',
|
||||
$firstPerfToTeamDiff,
|
||||
0
|
||||
),
|
||||
//send to greater than or within factor
|
||||
new ScheduleStep(
|
||||
'send to greater than or within factor',
|
||||
$firstTeamDiffComparison,
|
||||
0
|
||||
),
|
||||
@ -123,18 +123,18 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$currentForwardSchedulePiece =
|
||||
$this->scheduleSequence(
|
||||
[
|
||||
//team perf to perf diff
|
||||
new ScheduleStep(
|
||||
sprintf('team perf to perf diff %d', $i),
|
||||
$currentTeamPerfToTeamPerfDiff,
|
||||
0
|
||||
),
|
||||
//greater than or within result factor
|
||||
new ScheduleStep(
|
||||
sprintf('greater than or within result factor %d', $i),
|
||||
$currentTeamDiffComparison,
|
||||
0
|
||||
),
|
||||
//'team perf to perf diff factors
|
||||
new ScheduleStep(
|
||||
sprintf('team perf to perf diff factors [%d], 2', $i),
|
||||
$currentTeamPerfToTeamPerfDiff,
|
||||
2
|
||||
),
|
||||
@ -145,7 +145,8 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$forwardScheduleList[] = $currentForwardSchedulePiece;
|
||||
}
|
||||
|
||||
$forwardSchedule = new ScheduleSequence('forward schedule', $forwardScheduleList);
|
||||
//forward schedule
|
||||
$forwardSchedule = new ScheduleSequence($forwardScheduleList);
|
||||
|
||||
$backwardScheduleList = [];
|
||||
|
||||
@ -157,21 +158,21 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$comparisonFactor = $teamDifferencesComparisonLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
$performancesToDifferencesFactor = $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors[$totalTeamDifferences - 1 - $i];
|
||||
|
||||
//current backward schedule piece
|
||||
$currentBackwardSchedulePiece = new ScheduleSequence(
|
||||
'current backward schedule piece',
|
||||
[
|
||||
//teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0
|
||||
new ScheduleStep(
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 0', $i),
|
||||
$differencesFactor,
|
||||
0
|
||||
),
|
||||
//greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0
|
||||
new ScheduleStep(
|
||||
sprintf('greaterThanOrWithinResultFactors[totalTeamDifferences - 1 - %d] @ 0', $i),
|
||||
$comparisonFactor,
|
||||
0
|
||||
),
|
||||
//teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1
|
||||
new ScheduleStep(
|
||||
sprintf('teamPerformanceToPerformanceDifferenceFactors[totalTeamDifferences - 1 - %d] @ 1', $i),
|
||||
$performancesToDifferencesFactor,
|
||||
1
|
||||
),
|
||||
@ -180,18 +181,19 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer
|
||||
$backwardScheduleList[] = $currentBackwardSchedulePiece;
|
||||
}
|
||||
|
||||
$backwardSchedule = new ScheduleSequence('backward schedule', $backwardScheduleList);
|
||||
//backward schedule
|
||||
$backwardSchedule = new ScheduleSequence($backwardScheduleList);
|
||||
|
||||
$forwardBackwardScheduleToLoop =
|
||||
//forward Backward Schedule To Loop
|
||||
new ScheduleSequence(
|
||||
'forward Backward Schedule To Loop',
|
||||
[$forwardSchedule, $backwardSchedule]
|
||||
);
|
||||
|
||||
$initialMaxDelta = 0.0001;
|
||||
|
||||
//loop with max delta
|
||||
return new ScheduleLoop(
|
||||
sprintf('loop with max delta of %f', $initialMaxDelta),
|
||||
$forwardBackwardScheduleToLoop,
|
||||
$initialMaxDelta
|
||||
);
|
||||
|
@ -38,7 +38,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
static fn($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0),
|
||||
//Perf to Team Perf Step
|
||||
static fn($weightedSumFactor): ScheduleStep => new ScheduleStep($weightedSumFactor, 0),
|
||||
$localFactors
|
||||
),
|
||||
'all player perf to team perf schedule'
|
||||
@ -73,8 +74,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
|
||||
$localCurrentFactor = $currentFactor;
|
||||
$numberOfMessages = $localCurrentFactor->getNumberOfMessages();
|
||||
for ($currentIteration = 1; $currentIteration < $numberOfMessages; ++$currentIteration) {
|
||||
//team sum perf
|
||||
$allFactors[] = new ScheduleStep(
|
||||
'team sum perf @' . $currentIteration,
|
||||
$localCurrentFactor,
|
||||
$currentIteration
|
||||
);
|
||||
|
@ -55,7 +55,8 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
static fn($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0),
|
||||
//Prior to Skill Step
|
||||
static fn($prior): ScheduleStep => new ScheduleStep($prior, 0),
|
||||
$localFactors
|
||||
),
|
||||
'All priors'
|
||||
|
@ -57,7 +57,8 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
static fn($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0),
|
||||
//Skill to Perf step
|
||||
static fn($likelihood): ScheduleStep => new ScheduleStep($likelihood, 0),
|
||||
$localFactors
|
||||
),
|
||||
'All skill to performance sending'
|
||||
@ -70,7 +71,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer
|
||||
|
||||
return $this->scheduleSequence(
|
||||
array_map(
|
||||
static fn($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1),
|
||||
static fn($likelihood): ScheduleStep => new ScheduleStep($likelihood, 1),
|
||||
$localFactors
|
||||
),
|
||||
'All skill to performance sending'
|
||||
|
@ -124,7 +124,8 @@ class TrueSkillFactorGraph extends FactorGraph
|
||||
}
|
||||
}
|
||||
|
||||
return new ScheduleSequence('Full schedule', $fullSchedule);
|
||||
//Full schedule
|
||||
return new ScheduleSequence($fullSchedule);
|
||||
}
|
||||
|
||||
public function getUpdatedRatings(): RatingContainer
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DNW\Skills\Tests\FactorGraphs;
|
||||
|
||||
use DNW\Skills\FactorGraphs\ScheduleStep;
|
||||
use DNW\Skills\FactorGraphs\Factor;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ScheduleStepTest extends TestCase
|
||||
{
|
||||
public function testtoStringInterface(): void
|
||||
{
|
||||
$stub = $this->createStub(Factor::class);
|
||||
$ss = new ScheduleStep('dummy', $stub, 0);
|
||||
$this->assertEquals('dummy', (string)$ss);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user