I need to distribute objects with a defined width on a numberline, which is already populated with other objects. There should be no overlap of objects and I have several constraints. E.g. no two green blocks in a row. The objective is to distribute them in a way that all colored blocks are as left on the numberline as possible. The following picture illustrates this problem.

Is there a name for problems like this, and where to look for solutions and algorithms?