E.add_constraint(~p1_using_resource | ~p2_using_resource) # Finally, we can add constraints to tell the system which processes use which resources: # For example: # process 0 uses resource: E.add_constraint(r.get(0, 0)) # process 1 also uses resource E.add_constraint(r.get(1, 0)) # process 2 also uses resource E.add_constraint(r.get(2, 0)) # (So, processes 0, 1, and 2, cannot be run concurrently) return E if __name__ == "__main__": T = example_theory() print("\nSatisfiable: %s" % T.is_satisfiable()) #print("# Solutions: %d" % T.count_solutions()) print("solution:") solution = T.solve() for time in range(num_time_slots): for processor in range(num_processors): for process in range(num_processes): var_name = 'schedule_' + str(time) + '_' + str( processor) + '_' + str(process) print(var_name, solution[var_name]) #print(" Solution: %s" % T.solve())
print('holding is exclusive', constraint) E.add_constraint(constraint) for i in range(num_processes): for j in range(num_resources): # holding implies max constraint = ~h[i][j] | m[i][j] print('holding implies max', constraint) E.add_constraint(constraint) # hard code 2 processes and 2 resources for now: # These constraints ensure that the system is in a safe state E.add_constraint(~m[0][0] | ~h[1][0] | ~m[1][1] | ~h[0][1]) E.add_constraint(~m[0][1] | ~h[1][1] | ~m[1][0] | ~h[0][0]) return E if __name__ == "__main__": T = example_theory() print("\nSatisfiable: %s" % T.is_satisfiable()) print("# Solutions: %d" % T.count_solutions()) print(" Solution: %s" % T.solve()) print("\nVariable likelihoods:") print(" %s: %.2f" % ("each m", T.likelihood(m[0][0]))) # by symmetry print(" %s: %.2f" % ("each h", T.likelihood(h[0][0]))) # by symmetry print()