Advertisement
metalni

VI Vtora Labaratoriska - 1

Jun 30th, 2021
1,259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. from constraint import *
  2.  
  3. if __name__ == '__main__':
  4.  
  5.     # Define variables
  6.     problem = Problem()
  7.     domain_Participants = list()
  8.     domain_Team_leaders = list()
  9.     variables = list()
  10.  
  11.     num_Participants = int(input())
  12.     for i in range(num_Participants):
  13.         line = (input().split(" "))
  14.         domain_Participants.append(float(line[0]))
  15.         variables.append(line[1])
  16.  
  17.     num_Team_leaders = int(input())
  18.     for i in range(num_Team_leaders):
  19.         line = (input().split(" "))
  20.         domain_Team_leaders.append(float(line[0]))
  21.         variables.append(line[1])
  22.  
  23.     problem.addVariable("Team Leader", domain_Team_leaders)
  24.     problem.addVariable("Participant 1", domain_Participants)
  25.     problem.addVariable("Participant 2", domain_Participants)
  26.     problem.addVariable("Participant 3", domain_Participants)
  27.     problem.addVariable("Participant 4", domain_Participants)
  28.     problem.addVariable("Participant 5", domain_Participants)
  29.     problem.addConstraint(ExactSumConstraint(100.0))
  30.     problem.addConstraint(AllDifferentConstraint())
  31.     solution = problem.getSolution()
  32.  
  33.     Team_leader = None
  34.     Participant_1 = None
  35.     Participant_2 = None
  36.     Participant_3 = None
  37.     Participant_4 = None
  38.     Participant_5 = None
  39.  
  40.     count = 0
  41.     for v in domain_Participants + domain_Team_leaders:
  42.         if solution['Team Leader'] == v:
  43.             Team_leader = variables[count]
  44.         if solution['Participant 1'] == v:
  45.             Participant_1 = variables[count]
  46.         if solution['Participant 2'] == v:
  47.             Participant_2 = variables[count]
  48.         if solution['Participant 3'] == v:
  49.             Participant_3 = variables[count]
  50.         if solution['Participant 4'] == v:
  51.             Participant_4 = variables[count]
  52.         if solution['Participant 5'] == v:
  53.             Participant_5 = variables[count]
  54.         count += 1
  55.  
  56.     total = solution['Team Leader'] + solution['Participant 1'] + solution['Participant 2'] + solution[
  57.         'Participant 3'] + solution['Participant 4'] + solution['Participant 5']
  58.     print("Total score:", "%.1f" % total)
  59.     print("Team leader:", Team_leader)
  60.     print("Participant 1:", Participant_1)
  61.     print("Participant 2:", Participant_2)
  62.     print("Participant 3:", Participant_3)
  63.     print("Participant 4:", Participant_4)
  64.     print("Participant 5:", Participant_5)
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement