# How to formulate problems in the language of mathematical programming?

The question says it all. I am having difficulties formulating general problems (meaning no numbers just variables). When I read the solution, I understand but I can't figure how to formulate myself in new problems. I need some tips or what to look for, some guidance in general. By formulation I mean finding the objective to be minimized/maximized and the constraints. Here is an example with the solution (you can just look at the solution to understand what I mean):

Formulate the problem of finding an optimal timetable for a school. The timetable is represented by variables $$x_{i,j,k} \in \{0,1\}$$. The index $$i\in \{1, ...,6\}$$ stands for the timeslot (with the duration of one lesson) on a day from the morning to the late afternoon. The index $$j=\{1, ...,5\}$$ stands for a weekday. The index $$k\in \{1, ...,6\}$$ stands for the subject. The index $$\in \{1,2,3\}$$ stands for the classroom.The decision variable $$x_{i,j,k}$$ is set equal to 1 if subject $$k$$ is given in timeslot $$i$$ on day $$j$$. Otherwise $$x_{i,j,k}$$ is set equal to 0. Formulate the mathematical program under the following constraints: (C1) Subject 1,2 and 3 are given 6 timeslots per week, subjects 4, 5 and 6 only 3 timeslots per week. (C2) At every time, a classroom can be used only for one subject. (C3) The same subject cannot be taught in parallel at the same time. (C4) the same subject should not be taught more than two times per day. Moreover, the total number of lessons taught in timeslots 1, 5 and 6 should be minimized.

(The image has the solution)

• Welcome to OR.SE! I've edited your question to use MathJax. Please feel free to edit further if I've introduced any errors. – LarrySnyder610 Jan 29 '20 at 15:16
• If the optimization model is valid and you are interested to write your model in an AML (Algebraic modelling language), you could try using AMPL, GAMS or OPL. if you might write the model in the programming language like python, you could try some open-source solvers like PuLp, MIPCL, Pyomo and... . I hope it would be useful. – A.Omidi Jan 30 '20 at 6:07

This is quite a broad question, and I'm not sure you'll get the answers you need here. To learn how to formulate mathematical optimization problems takes learning and practice, and there's no concrete answer that we can provide on a Q&A site like this. Your best bet is to take a class that teaches or uses optimization modeling, or to learn from a good book.

Having said that, there are some relevant Q&As on this site that might help you:

You can also check out the questions tagged . Good luck!

• thank you for the information!! The links really helped. – paulaxa1 Feb 2 '20 at 14:18

Old joke (relevant here): A tourist asks a NYC cab driver "How do I get to Carnegie Hall?" Reply: "Practice, practice, practice". I second Larry's answer.

One other note: I suggest starting with small, easy models and working your way up. The mere sight of triple summations has been know to fry synapses. Start with problems where the solution has a small number of simple constraints. Formulate the model as best you can without looking at the solution (beyond a glance to ascertain that it's small / simple), then see how your model compares to the solution.

• "practice practice practice" :D – Kuifje Jan 30 '20 at 8:41
• Thank you for answering! Do you know if there any exercises of this type with their solutions online? – paulaxa1 Feb 2 '20 at 14:19
• I would look for introduction to mathematical programming courses in Coursera, edX and other MOOC platforms. Assuming they cover model building, there will likely be both lecture notes showing completed models and exercises with answers posted somewhere. Another place to look is lecture notes posted online by professors. – prubin Feb 2 '20 at 21:21