I'm new to Scilab (and programming in general). I'm trying to implement a Scilab code to solve the cutting stock problem aka 'bin packing'.
The problem: given 'n' items of sizes[] (a vector from s1 to sn), and same capacity for all bins (c=1000), I need to minimize the number of bins required to fit all items.
I'm trying the 'next item algorithm', i.e., pick the first item from the vector, put it in the bin, then pick the next item and try to put in the same bin, in case there is no enough space, then create another bin.
Actually I don't need help in improving the algorithm, but rather in implement the code for this specific one.
Here is what I've tried so far:
// 'n' is the number of items to be packed
// 'c' is the capacity (how much items fit in the bin)
// 'sizes' a vector containing the size of n items
// 'nbins' number of bins used so far
// 'bin_rem' space left in current bin
sizes=[400,401,402,403,404,405,406,408,409,411,428,450,482]
c=1000
n=length(sizes)
nbins = 0
bin_rem = c
function y = bins(sizes,c,n)
for i=0; i<n; i=i+1
if sizes[i] > bin_rem
nbins=nbins+1
bin_rem = c - sizes(i)
bin_rem = bin_rem - sizes(i)
end
endfunction
disp ("Number of bins needed "+string(bins([sizes,c,n])))
end
I'm stuck with this error below and have no idea on how to solve it.
at line 20 of executed file endfunction ^~~~~~~~~~~^ Error: syntax error, unexpected endfunction, expecting end
Any help?