コード例 #1
0
def test_daily(store):

    avails = get_availabilities()
    required_workers_mat=store.n_workers_table
    csps = create_daily_model(store)
    solver = BTS(csps)
    c_stime = time.time()
    tmpsoln = solver.bts_search(prop_GAC)


    for i, (res,con) in enumerate(tmpsoln):
        flag = True
        while (res == []) and flag:
            c,v = con
            print("the cons that could not be satisfied is {} and the var is{}".format(c,v))
            required_workers_mat, flag = modify_req_mat(required_workers_mat, c)
            if flag:
                print("try for less workers in {}".format(c))
                d = int((c.name)[3])
                new_daaily_csp = create_daily_model(store ,d-1)
                tbs = BT(new_daaily_csp)
                rest, cont = tbs.bt_search(prop_GAC)
                if rest:
                    for ss in new_daaily_csp.get_soln():
                        res.append(ss)
                else:
                    res = []
                    con = cont
    tot_time = time.time() - c_stime
    ttmpsoln = [x for (x,y) in tmpsoln]
    soln = fix_to_print(ttmpsoln, -1 )
    print('the total time is', tot_time)
    print('and the solution is:')
    print_schedule(soln,store)
    return tot_time, len(store.get_all_employees())
コード例 #2
0
def run_solver(propType,store, trace=False):
    # nworkers = 10
    # avails = get_availabilities()
    required_workers_mat=[[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1],[1,1,1]]
    # r0 = (required_workers_mat[0])
    # r0[2] = 3
    # r0[1] = 2
    # csp = create_model(avails,required_workers_mat)

    flag = True
    res = False
    c_stime = time.time()
    while (not res) and flag:
        csp = create_week_model(store)
        print("csp created")
        solver = BT(csp)
        if trace:
            solver.trace_on()
        if propType == 'BT':
            solver.bt_search(prop_BT)
        elif propType == 'FC':
            solver.bt_search(prop_FC)
        elif propType == 'GAC':

            res, cons = solver.bt_search(prop_GAC)
        if not res:
            if cons == None:
                print('finding solution took too long process terminated, now lets try BTS')
                return 100.0000001, len(store.get_all_employees())
            c,v = cons
            print("the cons that could not be satisfied is {} and the var is{}".format(c,v))
            print('relax the cons by reducing the num of workers for that shift.')
            required_workers_mat, flag = modify_req_mat(required_workers_mat, c)
            if flag:
                print("try for less workers in {}".format(c))
    tot_time = time.time() - c_stime
    if not flag and not res:
        print("couldn't find solution")

    else:
        print('the total time is', tot_time)
        tmpsoln = csp.get_soln()
        soln = fix_to_print(tmpsoln, store.nume_emp())
        print('and the solution is:')
        print_schedule(soln,store)
    return tot_time, len(store.get_all_employees())
コード例 #3
0
    def bts_search(self,propagator):
        sol_list = []
        for c in self.csp_list:
            solver = BT(c)
            res, cons = solver.bt_search(propagator)
            if res==False:
                n_sol_list = ([], cons)
            else:
                n_sol_list = ([x for x in (c.get_soln()) ], cons)
            sol_list.append(n_sol_list)

        return sol_list