Project scheduling using linear programming Project Scheduling. This problem deals with the creation of a project schedule; speciﬁcally, the project of building a house. 
The project has been divided into a set of jobs. The problem is to schedule the time at which each of these jobs should start and also to predict how long the project will take. Naturally, the objective is to complete the project as quickly as possible (time is money!). Over the duration of the project, some of the jobs can bedone concurrently. But, as the following table shows, certain jobs deﬁnitely can’t start until others are completed. 


*

*Job ___________Duration ______Preceeded by 


*

*Sign Contract    ____0 ____________– 

*Framing_______ 2 _____________1 

*Rooﬁng _______1_____________ 2 

*Siding ________3_____________ 2 

*Windows ______2.5____________ 4 

*Plumbing ______1.5 ____________4 

*Electrical _______2 ____________3,5 

*Inside Finishing ___4 ____________6,7 

*Outside Painting ___3 ___________3,5 

*Complete the Sale __ 0 ___________8,9



One possible schedule is the following: 


*

*Job______________________ Start Time 


*

*Sign Contract with Buyer______ 0 

*Framing _________________1 

*Rooﬁng _________________4 

*Siding __________________6 

*Windows ________________10 

*Plumbing ________________9 

*Electical _________________13 

*Inside Finishing ____________16 

*Outside Painting ___________14 

*Complete the Sale to Buyer ____21



With this schedule, the project duration is 21 weeks (the difference between the start times of jobs 9 and 0). 
To model the problem as a linear program, introduce the following decision variables: $t_{j}$ = the start time of job $j$.
(a) Write an expression for the objective function,which is to minimize the project duration. (b) For each job $j$, write a constraint for each job $i$ that must preceed $j$; the constraint should ensure that job $j$ doesn’t start until job $i$ is ﬁnished. These are called precedence constraints.
 A: Here's how I've tackled this part of a problem. Define a job as the following type of object (using electrical as an example):
{title: 'electrical', duration: 2, precedents: [3, 5]}

Then create the precedent constraints by looping through each job and precedent. (Pesudo code)
for j in jobs:
  for p in precedents:
     add_constraint(start_time_of_j >= start_time_of_p + duration_of_p)

Then create a start_time and an end_time variable, and setting them before and after all jobs. (This effectively makes start_time the minimum of all start_times and end_time the maximum of all start_times plus their respective durations.)
for j in jobs:
  add_constraint(start_time <= start_time_of_j)
  add_constraint(end_time >= start_time_of_j + duration_of_j)

Lastly, set your objective function to minimize total time.
set_objective(minimize, end_time - start_time)

I found it helped to add the following constraint too
add_constraint(start_time == 0)

A: A project is defined as a set consisting of a certain number of activities also called tasks or jobs that must be carried out in a given order. In other words, there are precedence constraints on activities, typically an activity cannot start before others are completed. Each activity is also characterized by an execution time. A project is associated with a graphic representation consisting of an oriented graph: each activity is represented by an edge whose extreme nodes represent the beginning and end of the activity itself.
The duration of the project is equal to $ t_f - t_0 $ where $ t_f $  is the time to complete at the latest the activities that flow into the terminal node. Let conventionally be $ t_0=0$ the initial time at which project starts, the problem of determining the minimum time required to fully complete the project can be formalized as follow. Suppose project is made of m activities and n nodes,
$ min \left \{ t_f \right \} $
Constraints:
$ \left\{ \begin{array}{l} 
t_j \ge t_i  \ + p_{i,j} \\
t_i  \ge 0   \forall \ i=1,...,n  \\
\end{array} \right.$
$ t_i $ is the starting time of jobs for which the i-th node is the direct predecessor of the j-th node
$ t_{j} $ is the finishing time of jobs flowing into j-th node
$ p_{i,j} $ represents the duration of job with regard to edge (i;j)
The $ t_j \ge t_i \ + p_ {i, j} $ constraint designates that task j-th cannot start before the preceding tasks i-th have finished. Note that the start time of an activity leaving a node coincides with the end time of the activities entering the node itself. The objective of the model is to minimize the overall duration of the project and the solution of the linear problem provides the start times of all m jobs in compliance with the m precedence constraints.
