{"id":23038243,"url":"https://github.com/rugleb/phpgpss","last_synced_at":"2025-04-02T23:28:34.364Z","repository":{"id":62538090,"uuid":"133133923","full_name":"rugleb/phpgpss","owner":"rugleb","description":"PHP analog of the GPSS modeling language","archived":false,"fork":false,"pushed_at":"2018-10-13T20:40:02.000Z","size":508,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T13:44:06.507Z","etag":null,"topics":["analyze","gpss","modeling","php","simulation"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/rugleb/phpgpss","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rugleb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-12T09:56:42.000Z","updated_at":"2018-10-13T20:40:04.000Z","dependencies_parsed_at":"2022-11-02T15:30:22.983Z","dependency_job_id":null,"html_url":"https://github.com/rugleb/phpgpss","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fphpgpss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fphpgpss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fphpgpss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rugleb%2Fphpgpss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rugleb","download_url":"https://codeload.github.com/rugleb/phpgpss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246909315,"owners_count":20853381,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analyze","gpss","modeling","php","simulation"],"created_at":"2024-12-15T18:17:16.892Z","updated_at":"2025-04-02T23:28:34.348Z","avatar_url":"https://github.com/rugleb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"**phpGPSS** - a library written in PHP, is an analog of the GPSS modeling language. \nUsing this library, you can easily simulate and analyze your system, find out how effective your processes are.\n\nFor example, create a traffic simulator.\n\nFirst of all, we define the transact - **Car**:\n\n```php\nuse GPSS\\Foundation\\Transact\\Transact;\n\n/**\n * The Car class.\n */\nclass Car extends Transact\n{\n    //\n}\n```\n\nNext, define a **Generator** that will generate new **Transacts** (in our case **Car**) at a certain point in time:\n\n```php\n\nuse GPSS\\Foundation\\Generator;\n\n/**\n * The CarGenerator class.\n *\n * @package App\n */\nclass CarGenerator extends Generator\n{\n\n    /**\n     * Get delay time.\n     *\n     * @return int\n     */\n    public function getDelayTime(): int\n    {\n        return rand(5, 9) * 10;\n    }\n\n    /**\n     * Get transact class name.\n     *\n     * @return string\n     */\n    public function getTransactName(): string\n    {\n        return Car::class;\n    }\n\n}\n```\n\nNext, define the **Service** that will handle our **Car** transacts created by the **CarGenerator**.  \nHere we added a **HasModel**, which will allow us to use the **Queue** to enter the device: **RoadService**.  \nThe most important punctuation is the definition of the **handle** method, which contains the logic of transaction processing by the service.  \nAlso, we set the transaction processing time in the device, for which the method **getDelayTime**.  \n```php\nuse GPSS\\Foundation\\Service\\Service;\nuse GPSS\\Foundation\\Service\\HasQueue;\nuse GPSS\\Foundation\\Transact\\Transact;\n\n/**\n * The RoadService class.\n */\nclass RoadService extends Service\n{\n    use HasQueue;\n\n    /**\n     * Handle input transact.\n     *\n     * @param Transact $transact\n     * @return mixed\n     */\n    public function handle(Transact \u0026$transact)\n    {\n        if ($this-\u003eisFree()) {\n            return $this-\u003eseize($transact);\n        }\n\n        if ($this-\u003eisProcessing($transact)) {\n\n            if ($this-\u003ecanRelease($transact)) {\n                return $this-\u003erelease()-\u003eterminate($transact);\n            }\n\n            return $this;\n        }\n        \n        return $this-\u003equeue($transact);\n    }\n\n    /**\n     * Get delay time.\n     *\n     * @return int\n     */\n    public function getDelayTime(): int\n    {\n        return rand(2, 8) * 10;\n    }\n\n}\n```\n\nNow, everything is ready. It remains to create an instance of the **Model** and run the simulation.  \nPay attention to the **config** that the **Model** accepts.  \nThis config connects services, transactions and generators.\n\n```php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse App\\Car;\nuse App\\RoadService;\nuse App\\CarGenerator;\nuse GPSS\\Foundation\\Model;\n\n$config = [\n    'map' =\u003e [\n        Car::class =\u003e RoadService::class,\n    ],\n    'services' =\u003e [\n        RoadService::class,\n    ],\n    'generators' =\u003e [\n        CarGenerator::class,\n        CarGenerator::class,\n    ],\n];\n\n$model = new Model($config);\n$model-\u003esimulate(200);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frugleb%2Fphpgpss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frugleb%2Fphpgpss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frugleb%2Fphpgpss/lists"}