Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/velliz/timetables
Timetable algorithm implemented with 2 dimensional cartesius diagram
https://github.com/velliz/timetables
algorithm php-library timetable
Last synced: 25 days ago
JSON representation
Timetable algorithm implemented with 2 dimensional cartesius diagram
- Host: GitHub
- URL: https://github.com/velliz/timetables
- Owner: Velliz
- License: mit
- Created: 2018-11-14T02:13:52.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T02:30:51.000Z (about 6 years ago)
- Last Synced: 2024-12-02T12:55:22.250Z (26 days ago)
- Topics: algorithm, php-library, timetable
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Timetables
Timetable algorithm implemented with 2 dimensional cartesius diagram.
### Install
```bash
composer require velliz/timetables
```### Usage
**Criteria**
Instance a criteria for X and Y dimensions with provided example.
You can have your customized **TimeDatum** and **RoomDatum** class with extending it to ```Datum``` abstraction.```php
$criteriaX = new \tests\TimeDatum();
$criteriaX->data = 5;
$criteriaX->closeData = array(4, 6);
``````php
$criteriaY = new \tests\RoomDatum();
$criteriaY->data = 93;
$criteriaY->closeData = array(92, 94);
``````$criteriaY->data``` is what exactly you want to search and ```$criteriaY->closeData```
is acceptable if the data not found in the XY dimensions.**Driver**
```php
$timetable = new \timetables\TimetableDriver();
```**Dimensions**
This example create a 900 length size random **TimeDatum** with range value from 0 to 100.
```php
$dimenX = new timetables\cartesius\Dimensions();
for ($i = 0; $i < 900; $i++) {
$data = new \tests\TimeDatum();
$data->data = rand(0, 100);
$timetable->addDimenX($data);
}
```This example create a 100 length size random **RoomDatum** with range value from 0 to 100.
```php
$dimenY = new timetables\cartesius\Dimensions();
for ($i = 0; $i < 500; $i++) {
$data = new \tests\RoomDatum();
$data->data = rand(0, 100);
$timetable->addDimenY($data);
}
```**Results**
Algorithm will find a match **TimeDatum** with value 5 and **RoomDatum** with value 93.
```php
$result = $timetable->setCriteriaX($criteriaX)->setCriteriaY($criteriaY)->CalculateTimeTable();
```And result from calculation:
```php
array(6) {
["BestX"]=>
int(893)
["BestY"]=>
int(83)
["Criteria"]=>
array(2) {
["X"]=>
int(5)
["Y"]=>
int(93)
}
["Result"]=>
array(2) {
["X"]=>
int(5)
["Y"]=>
int(93)
}
["Iteration"]=>
int(13812)
["Remark"]=>
string(5) "CLEAR"
}
```### Calculation
To create custom comparison rules, you can implement custom classes and *extends* it to **Datum**
```php
class CustomRoomDatum extends Datum
```and implements **CalculateFits** function.
```php
public function CalculateFits(Datum $comparator)
{
//simple comparison logic
if ($comparator->data === $this->data) {
return Datum::EQUALS;
} else if (in_array($this->data, $comparator->closeData)) {
return Datum::CLOSE;
}
return Datum::NOT_MATCH;
}
```* ```$comparator->data``` is your criteria passed from function parameter
* ```$this->data``` is primary usage for comparison and populated from the **Dimensions**Then return a constant provided:
* ```Datum::EQUALS``` if data is match
* ```Datum::CLOSE``` if data close matched
* ```Datum::NOT_MATCH``` if data not match