How can I minimize costs(setup time,violation time) in python?

I got 10 demand lists on csv file.

Each demand list has 100 demand informations which has product type, processing time, and duedate.

I have 20 machine and I must produce the demands on these machines.

If I start producing different types of products on the same machine, I will have a setup time of 2 hours, and if I produce the product after the duedate, I will have violation time.

Please give me an idea to minimize setup time and vibration time in python to produce the product.

God bless you! Have a good day!

Source: Python Questions