family_camp/schedule/timetable_cps.py
def possible_family_arrangements_for_activity(activity, groups):
    """Return the allowable arrangements of families for the given activity.
    """

    # Get the indexes for all families that requested this activity.
    filtered_groups = [_ for _ in range(len(groups)) if len(groups[_].activities[activity.name]) > 0]

    # - number of members of each family that want the activity
    members = [len(groups[_].activities[activity.name]) for _ in filtered_groups]

    solver = pywrapcp.Solver("Act")

    # x = [ 0,1,1,0 ] - boolean for each family
    x = [solver.IntVar(0, 1, "x%d" % i) for i in range(len(filtered_groups))]


    #
    # sum (a[i] * b[i] ) for all i <= limit of activity
    solver.Add(solver.ScalProd(x, members) <= activity.limit)

    all_solutions = solver.AllSolutionCollector()
    all_solutions.Add(x)

    db = solver.Phase(x,
                      solver.INT_VAR_SIMPLE,
                      solver.INT_VALUE_SIMPLE)

    solver.Solve(db, all_solutions)

    # Retrieve the solutions
    number_solutions = all_solutions.SolutionCount()

    print("Number of solutions for activity: {} - {}".format(number_solutions, activity.name))

    #solution = solver.Assignment()

    # build a list of the possible solutions.
    options = [0] * number_solutions
    for index in range(number_solutions):
        solution = all_solutions.Solution(index)
        option = [0] * len(groups)
        for grp in range(len(filtered_groups)):
            option[filtered_groups[grp]] = solution.Value(x[grp])
        options[index] = option

    solver.EndSearch()

    return options
Return the allowable arrangements of families for the given activity.
    
Return the allowable arrangements of families for the given activity.
Return the allowable arrangements of families for the given activity .
def possible_family_arrangements_for_activity(activity, groups):
    filtered_groups = [_ for _ in range(len(groups)) if len(groups[_].activities[activity.name]) > 0]
    members = [len(groups[_].activities[activity.name]) for _ in filtered_groups]
    solver = pywrapcp.Solver("Act")
    x = [solver.IntVar(0, 1, "x%d" % i) for i in range(len(filtered_groups))]
     sum (a[i] * b[i] ) for all i <= limit of activity
    solver.Add(solver.ScalProd(x, members) <= activity.limit)
    all_solutions = solver.AllSolutionCollector()
    all_solutions.Add(x)
    db = solver.Phase(x,
                      solver.INT_VAR_SIMPLE,
                      solver.INT_VALUE_SIMPLE)
    solver.Solve(db, all_solutions)
     Retrieve the solutions
    number_solutions = all_solutions.SolutionCount()
    print("Number of solutions for activity: {} - {}".format(number_solutions, activity.name))
    solution = solver.Assignment()
     build a list of the possible solutions.
    options = [0] * number_solutions
    for index in range(number_solutions):
        solution = all_solutions.Solution(index)
        option = [0] * len(groups)
        for grp in range(len(filtered_groups)):
            option[filtered_groups[grp]] = solution.Value(x[grp])
        options[index] = option
    solver.EndSearch()
    return options
def possible_family_arrangements_for_activity ( activity , groups ) : filtered_groups = [ _ for _ in range ( len ( groups ) ) if len ( groups [ _ ] . activities [ activity . name ] ) > 0 ] members = [ len ( groups [ _ ] . activities [ activity . name ] ) for _ in filtered_groups ] solver = pywrapcp . Solver ( "Act" ) x = [ solver . IntVar ( 0 , 1 , "x%d" % i ) for i in range ( len ( filtered_groups ) ) ] solver . Add ( solver . ScalProd ( x , members ) <= activity . limit ) all_solutions = solver . AllSolutionCollector ( ) all_solutions . Add ( x ) db = solver . Phase ( x , solver . INT_VAR_SIMPLE , solver . INT_VALUE_SIMPLE ) solver . Solve ( db , all_solutions ) number_solutions = all_solutions . SolutionCount ( ) print ( "Number of solutions for activity: {} - {}" . format ( number_solutions , activity . name ) ) options = [ 0 ] * number_solutions for index in range ( number_solutions ) : solution = all_solutions . Solution ( index ) option = [ 0 ] * len ( groups ) for grp in range ( len ( filtered_groups ) ) : option [ filtered_groups [ grp ] ] = solution . Value ( x [ grp ] ) options [ index ] = option solver . EndSearch ( ) return options
Return the allowable arrangements of families for the given activity.
Return the allowable arrangements of families for the given activity .
"""Return the allowable arrangements of families for the given activity.
    """ # Get the indexes for all families that requested this activity. # - number of members of each family that want the activity # x = [ 0,1,1,0 ] - boolean for each family # # sum (a[i] * b[i] ) for all i <= limit of activity # Retrieve the solutions #solution = solver.Assignment() # build a list of the possible solutions.
activity
groups