Your specific task is could be easily brute forced, check it online: https://3v4l.org/dQmdb
Here is a code:
<?php
// Examples:
// Door 2000 1845 3000
// 615mm panel 1 3 5
// 495mm panel 3 0 0
// panel loss 100 0 75
function calcOptimalPanels ($doorHeight) {
$bigHeight = 615;
$smallHeight = 495;
$bigFit = floor($doorHeight / $bigHeight);
$smallFit = floor($doorHeight / $smallHeight);
$options = [];
for ($big = 0; $big <= $bigFit; $big++) {
for ($small = 0; $small <= $smallFit; $small++) {
$waste = $bigHeight * $big + $smallHeight * $small - $doorHeight;
if ($waste === 0) // Get first combination without waste
return getFormattedResult($big, $small, $waste);
if ($waste > 0) // Omit combinations smaller then door
continue;
$options[$waste] = getFormattedResult($big, $small, $waste);
}
}
$minWaste = min(array_keys($options));
return $options[$minWaste];
}
function getFormattedResult($big, $small, $waste) {
return ['615mm' => $big, '495mm' => $small, 'waste' => $waste];
}
echo '2000: ' . json_encode(calcOptimalPanels(2000)) . "\n";
echo '1845: ' . json_encode(calcOptimalPanels(1845)) . "\n";
echo '2340: ' . json_encode(calcOptimalPanels(1845 + 495)) . "\n";
echo '3000: ' . json_encode(calcOptimalPanels(3000)) . "\n";
// Result:
// 2000: {"615mm":1,"495mm":3,"waste":100}
// 1845: {"615mm":3,"495mm":0,"waste":0}
// 2340: {"615mm":3,"495mm":1,"waste":0}
// 3000: {"615mm":1,"495mm":5,"waste":90}
My previous answer is not correct but I leave it as an example of our love to overcomplicate things.
Old answer
This is a classic 1D Cutting stock problem which can be formulated as an integer linear programming problem.
You should be aware that this is an NP-complete problem:
This basically means that their is no way of being guaranteed the best solution without checking every possible solution. This is not to say that a solution reached by one of the following algorithms is not optimal, it may be.
With given info in mind, you have to implement an algorithm yourself: https://neos-guide.org/content/cutting-stock-problem
and video: https://www.youtube.com/watch?v=NoiPrt4OsQA
If you desperately want to leverage machine learning then check genetic algorithm: https://github.com/ffsantos92/2d-cutting-stock-problem