Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rugleb/phpgpss
PHP analog of the GPSS modeling language
https://github.com/rugleb/phpgpss
analyze gpss modeling php simulation
Last synced: 9 days ago
JSON representation
PHP analog of the GPSS modeling language
- Host: GitHub
- URL: https://github.com/rugleb/phpgpss
- Owner: rugleb
- License: mit
- Created: 2018-05-12T09:56:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-13T20:40:02.000Z (about 6 years ago)
- Last Synced: 2024-04-29T17:06:53.074Z (8 months ago)
- Topics: analyze, gpss, modeling, php, simulation
- Language: PHP
- Homepage: https://packagist.org/packages/rugleb/phpgpss
- Size: 496 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**phpGPSS** - a library written in PHP, is an analog of the GPSS modeling language.
Using this library, you can easily simulate and analyze your system, find out how effective your processes are.For example, create a traffic simulator.
First of all, we define the transact - **Car**:
```php
use GPSS\Foundation\Transact\Transact;/**
* The Car class.
*/
class Car extends Transact
{
//
}
```Next, define a **Generator** that will generate new **Transacts** (in our case **Car**) at a certain point in time:
```php
use GPSS\Foundation\Generator;
/**
* The CarGenerator class.
*
* @package App
*/
class CarGenerator extends Generator
{/**
* Get delay time.
*
* @return int
*/
public function getDelayTime(): int
{
return rand(5, 9) * 10;
}/**
* Get transact class name.
*
* @return string
*/
public function getTransactName(): string
{
return Car::class;
}}
```Next, define the **Service** that will handle our **Car** transacts created by the **CarGenerator**.
Here we added a **HasModel**, which will allow us to use the **Queue** to enter the device: **RoadService**.
The most important punctuation is the definition of the **handle** method, which contains the logic of transaction processing by the service.
Also, we set the transaction processing time in the device, for which the method **getDelayTime**.
```php
use GPSS\Foundation\Service\Service;
use GPSS\Foundation\Service\HasQueue;
use GPSS\Foundation\Transact\Transact;/**
* The RoadService class.
*/
class RoadService extends Service
{
use HasQueue;/**
* Handle input transact.
*
* @param Transact $transact
* @return mixed
*/
public function handle(Transact &$transact)
{
if ($this->isFree()) {
return $this->seize($transact);
}if ($this->isProcessing($transact)) {
if ($this->canRelease($transact)) {
return $this->release()->terminate($transact);
}return $this;
}
return $this->queue($transact);
}/**
* Get delay time.
*
* @return int
*/
public function getDelayTime(): int
{
return rand(2, 8) * 10;
}}
```Now, everything is ready. It remains to create an instance of the **Model** and run the simulation.
Pay attention to the **config** that the **Model** accepts.
This config connects services, transactions and generators.```php
require_once __DIR__ . '/vendor/autoload.php';
use App\Car;
use App\RoadService;
use App\CarGenerator;
use GPSS\Foundation\Model;$config = [
'map' => [
Car::class => RoadService::class,
],
'services' => [
RoadService::class,
],
'generators' => [
CarGenerator::class,
CarGenerator::class,
],
];$model = new Model($config);
$model->simulate(200);
```