Is there anyway to improve with how this code is structured into functions? Is the coding style compliant, and what can be improved beyond this?def add_lower_intuitive_relation(gurobi_model, Leg1, Leg2, lower_bound, eval_func, name=):    for first_departure in xrange(Leg1.latest_departure_time - Leg1.earliest_departure_time + 1):        add_constraint = True        linexprleft = gurobipy.LinExpr()        linexprleft.addTerms(1.0, Leg1.gurobi_variables[first_departure])        linexprright = gurobipy.LinExpr()        for second_departure in xrange(Leg2.latest_departure_time - Leg2.earliest_departure_time + 1):            if lower_bound <= eval_func(Leg1.earliest_departure_time + first_departure,                                        Leg2.earliest_departure_time + second_departure, Leg1, Leg2):                if second_departure == 0:                    add_constraint = False                    break                linexprright.addTerms(1.0, Leg2.gurobi_variables[second_departure])        if add_constraint:            gurobi_model.addConstr(linexprleft,gurobipy.GRB.LESS_EQUAL,linexprright,name)def add_lower_tu_relation(gurobi_model, Leg1, Leg2,lower_bound, eval_func, name=):    linexpr_cummulative = gurobipy.LinExpr()    for first_departure in xrange(Leg1.latest_departure_time - Leg1.earliest_departure_time + 1):        linexpr_cummulative.addTerms(1.0, Leg1.gurobi_variables[first_departure])    for first_departure in xrange(Leg1.latest_departure_time - Leg1.earliest_departure_time + 1):        add_constraint = True        linexprright = gurobipy.LinExpr()        for second_departure in xrange(Leg2.latest_departure_time - Leg2.earliest_departure_time + 1):            if lower_bound <= eval_func(Leg1.earliest_departure_time + first_departure,                                        Leg2.earliest_departure_time + second_departure, Leg1, Leg2):                if second_departure == 0:                    add_constraint = False                    break                linexprright.addTerms(1.0, Leg2.gurobi_variables[second_departure])        if add_constraint:            gurobi_model.addConstr(linexpr_cummulative,gurobipy.GRB.LESS_EQUAL,linexprright,name)        linexpr_cummulative.addTerms(-1.0, Leg1.gurobi_variables[first_departure])def add_upper_tu_relation(gurobi_model, Leg1, Leg2, upper_bound, eval_func, name=):    linexpr_cummulative = gurobipy.LinExpr()    for second_departure in xrange(Leg2.latest_departure_time - Leg2.earliest_departure_time + 1):        linexpr_cummulative.addTerms(1.0, Leg2.gurobi_variables[second_departure])    for second_departure in xrange(Leg2.latest_departure_time - Leg2.earliest_departure_time + 1):        add_constraint = True        linexprright = gurobipy.LinExpr()        for first_departure in xrange(Leg1.latest_departure_time - Leg1.earliest_departure_time + 1):            if eval_func(Leg1.earliest_departure_time + first_departure,                         Leg2.earliest_departure_time + second_departure, Leg1, Leg2) <= upper_bound:                if second_departure == 0:                    add_constraint = False                    break                linexprright.addTerms(1.0, Leg1.gurobi_variables[first_departure])        if add_constraint:            gurobi_model.addConstr(linexpr_cummulative,gurobipy.GRB.LESS_EQUAL,linexprright,name)        linexpr_cummulative.addTerms(-1.0,Leg2.gurobi_variables[second_departure])def add_lower_relation(gurobi_model, Leg1, Leg2,lower_bound, eval_func, args, name=):    if args.improved_timetable_formulation == 0:        add_lower_intuitive_relation(gurobi_model,Leg1,Leg2,lower_bound,eval_func,name=)    else:        add_lower_tu_relation(gurobi_model,Leg1,Leg2,lower_bound,eval_func,name=)def add_lower_and_upper_intuitive_relation(gurobi_model, Leg1, Leg2, lower_bound, upper_bound, eval_func, name=):    for first_departure in xrange(Leg1.latest_departure_time - Leg1.earliest_departure_time + 1):        linexprleft = gurobipy.LinExpr()        linexprleft.addTerms(1.0, Leg1.gurobi_variables[first_departure])        linexprright = gurobipy.LinExpr()        for second_departure in xrange(Leg2.latest_departure_time - Leg2.earliest_departure_time + 1):            distance = eval_func(Leg1.earliest_departure_time + first_departure,                                 Leg2.earliest_departure_time + second_departure, Leg1, Leg2)            if lower_bound <= distance and distance <= upper_bound:                linexprright.addTerms(1.0, Leg2.gurobi_variables[second_departure])        gurobi_model.addConstr(linexprleft,gurobipy.GRB.LESS_EQUAL,linexprright,name)def add_lower_and_upper_tu_relation(gurobi_model, Leg1, Leg2, lower_bound, upper_bound, eval_func, name=):    add_lower_tu_relation(gurobi_model,Leg1,Leg2,lower_bound,eval_func,name)    add_upper_tu_relation(gurobi_model,Leg1,Leg2,upper_bound,eval_func,name)def add_lower_and_upper_relation(gurobi_model, Leg1, Leg2, lower_bound, upper_bound, eval_func, args, name=):    if args.improved_timetable_formulation == 0:        add_lower_and_upper_intuitive_relation(gurobi_model, Leg1, Leg2, lower_bound, upper_bound, eval_func, name=)    else:        add_lower_and_upper_tu_relation(gurobi_model,Leg1,Leg2,lower_bound,upper_bound,eval_func,name=)def minimium_waiting_time_eval_func(depart1, depart2, Leg1, Leg2):    return depart2 - (depart1 + Leg1.travel_time)def minimium_headway_depart_time_eval_func(depart1, depart2, Leg1, Leg2):    return depart2 - depart1def minimium_headway_arrival_time_eval_func(depart1, depart2, Leg1, Leg2):    return (depart2 + Leg2.travel_time) - (depart1 + Leg1.travel_time)def connection_time_eval_func(depart1, depart2, Leg1, Leg2):    return depart2 - (depart1 + Leg1.travel_time)add_lower_relation calls either add_lower_intuitive_relation or add_lower_tu_relation depending on the given arguments args.add_lower_and_upper_relation calls add_lower_and_upper_tu_relation or add_lower_and_upper_intuitive_relation.I have a one line function to pass the eval_func to the functions. I wanted this so the function is easily extend to different eval_functions. 
Choosing different Version of a model
python;python 2.7