I've implemented interactive coloring demo in JavaScript:
http://killerstorm.xen.prgmr.com/alex/color.htmlTo try it, select colors and values of inputs, e.g.
Red 1
Blue 1
Uncolored 1
Then fill amounts of outputs, but do not fill colors, e.g.
1
1
1
Then press button "compute", it will fill colors of outputs. If sum(outputs)>sum(inputs) it is reported in alert and outputs are not filled.
There is a list of possible errors/warnings in bottom of screen. If it says "false" that means it's OK, if it says "true" that means that there is error/warning.
Whether these errors/warnings matter depends on application.
Here is code:
https://gist.github.com/3807220 (below HTML)
Unfortunately validation code cluttered algo code so it's hard to follow it, but actually changes to handle zero-valued inputs/outputs were minimal.
I think it's probably better to have coloring and validation code separate, i.e. do coloring first and then run validation checks on it.
So I don't recommend reading code in this version, it's ugly.