Created
May 18, 2022 13:04
-
-
Save MarcinGladkowski/dd378d4268d639d51efcbf314f9d45ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dysponujesz zestawem zadań, a każde z nich ma format: | |
* | |
* [ | |
* 'name': string, | |
* 'resources': list of strings, | |
* 'payoff': float | |
* ] | |
* | |
* Każde zadanie zapewnia pewną zapłatę po jego wykonaniu i wymaga zestawu zasobów do jego wykonania. | |
* Jeśli dwa zadania wymagają tego samego zasobu, to są one niekompatybilne. | |
* Jeśli dwa zadania są niekompatybilne, to maszyna nie może wykonać obu jednocześnie. | |
* | |
* Przykłady zadań: | |
* | |
* [ | |
* {"name": "picture 1", "payoff": 2.1, "resources": ["resource 5", "resource 2"]}, | |
* {"name": "picture 2", "payoff": 4.5, "resources": ["resource 5", "resource 4", "resource 1"]}, | |
* {"name": "fsck", "payoff": 0.48, "resources": ["resource 4", "resource 2", "resource 3"]}, | |
* {"name": "clean", "payoff": 3.64, "resources": ["resource 5", "resource 6"]}, | |
* {"name": "picture 3", "payoff": 5.92, "resources": ["resource 6", "resource 3", "resource 4", "resource 1", "resource 2"]}, | |
* {"name": "backup", "payoff": 1.85, "resources": ["resource 4", "resource 6"]}, | |
* {"name": "clean", "payoff": 0.38, "resources": ["resource 3", "resource 2"]}, | |
* {"name": "clean camera", "payoff": 4.97, "resources": ["resource 6", "resource 3", "resource 4"]}, | |
* {"name": "clean motor", "payoff": 2.95, "resources": ["resource 4", "resource 6", "resource 2"]}, | |
* {"name": "picture 4", "payoff": 3.78, "resources": ["resource 5", "resource 4", "resource 2", "resource 1"]} | |
* ] | |
* | |
* Najlepszym podzadaniem dla przykładowych zadań jest: | |
* | |
* [ | |
* ['name': 'clean camera', 'payoff': 4.97, 'resources': ['resource 6', 'resource 4', 'resource 3']], | |
* ['name': 'picture 1', 'payoff': 2.1, 'resources': ['resource 2', 'resource 5']] | |
* ] | |
* | |
* Twój cel: | |
* Opracować system, który określi, jakie zadania musi wykonać maszyna, aby zmaksymalizować wypłatę. To znaczy, znaleźć podzbiór zadań w taki sposób, aby wypłata była maksymalna, a wszystkie zadania w otrzymanym zbiorze były zgodne. | |
*/ | |
$procedures = [ | |
["name" => "picture 1", "payoff" => 2.1, "resources" => ["resource 5", "resource 2"]], | |
["name" => "picture 2", "payoff" => 4.5, "resources" => ["resource 5", "resource 4", "resource 1"]], | |
["name" => "fsck", "payoff" => 0.48, "resources" => ["resource 4", "resource 2", "resource 3"]], | |
["name" => "clean", "payoff" => 3.64, "resources" => ["resource 5", "resource 6"]], | |
["name" => "picture 3", "payoff" => 5.92, "resources" => ["resource 6", "resource 3", "resource 4", "resource 1", "resource 2"]], | |
["name" => "backup", "payoff" => 1.85, "resources" => ["resource 4", "resource 6"]], | |
["name" => "clean", "payoff" => 0.38, "resources" => ["resource 3", "resource 2"]], | |
["name" => "clean camera", "payoff" => 4.97, "resources" => ["resource 6", "resource 3", "resource 4"]], | |
["name" => "clean motor", "payoff" => 2.95, "resources" => ["resource 4", "resource 6", "resource 2"]], | |
["name" => "picture 4", "payoff" => 3.78, "resources" => ["resource 5", "resource 4", "resource 2", "resource 1"]] | |
]; | |
function findMaxPayoff(array $procedures): array | |
{ | |
return []; | |
} | |
assert(findMaxPayoff($procedures) === [ | |
["name" => "picture 1", "payoff" => 2.1, "resources" => ["resource 5", "resource 2"]], | |
["name" => "clean camera", "payoff" => 4.97, "resources" => ["resource 6", "resource 3", "resource 4"]], | |
], "Wrong answerd"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment