SHARE
TWEET

Untitled

a guest May 24th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. def schrage():
  3.     mega_maszyna = []
  4.  
  5.     file_handle = open('data2.txt', 'r')
  6.  
  7.     lines_list = file_handle.readlines()
  8.  
  9.     zadania, maszyna = (int(val) for val in lines_list[0].split())
  10.  
  11.     mega_kursor = [0] * maszyna
  12.  
  13.     dane = [[int(val) for val in line.split()] for line in lines_list[1:]]
  14.  
  15.     for i in range(1, maszyna + 1):
  16.         mini_maszyna = [0] * zadania
  17.  
  18.         j = i
  19.         for i in range(0, zadania):
  20.             mini_maszyna[i] = dane[i][j - 1]
  21.  
  22.         mega_maszyna.append(mini_maszyna)
  23.  
  24.     t = 0
  25.     k = 0
  26.     c_max = 0
  27.     G = [];
  28.     N = list(range(0, zadania))
  29.     lista_pomocnicza = []
  30.     pi = [0] * zadania
  31.     r = mega_maszyna[0]
  32.     p = mega_maszyna[1]
  33.     q = mega_maszyna[2]
  34.  
  35.     rnowe = r[::]
  36.     pnowe = p[::]
  37.     qnowe = q[::]
  38.     globals()['rnowe'] = rnowe
  39.     globals()['pnowe'] = pnowe
  40.     globals()['qnowe'] = qnowe
  41.  
  42.     # --------------------------DEFINICJE--------------------------#
  43.  
  44.     q_kopia = q[::]
  45.     Q = []
  46.     j = []
  47.     while ((G != []) or (N != [])):
  48.  
  49.         while ((N != []) and (min(value for value in r if value != None) <= t)):
  50.             e = min(value for value in r if value != None)
  51.             e_arg = r.index(e)
  52.             r[e_arg] = None
  53.  
  54.             G.append(e_arg)
  55.             N.remove(e_arg)
  56.  
  57.             j.append(e_arg)
  58.  
  59.         for i in range(0, len(G)):
  60.             x = q[G[i]]
  61.             Q.append(x)
  62.  
  63.  
  64.         if G == []:
  65.             t = min(value for value in r if value != None)
  66.  
  67.         else:
  68.             e = max(value for value in Q if value != None)
  69.  
  70.             eq = Q.index(e)
  71.             e_arg = G[eq]
  72.  
  73.             q_kopia[e_arg] = None
  74.  
  75.             pi[k] = e_arg
  76.             k = k + 1
  77.             t = t + p[e_arg]
  78.             c_max = max(c_max, t + q[e_arg])
  79.  
  80.             G.remove(e_arg)
  81.  
  82.  
  83.         Q = []
  84.         globals()['c_max'] = c_max
  85.         globals()['pi'] = pi
  86.         globals()['zadania'] = zadania
  87.         globals()['j_arg'] = e_arg
  88.         globals()['t'] = t
  89.         globals()['j'] = e
  90.         globals()['r'] = r
  91.         globals()['p'] = p
  92.         globals()['q'] = q
  93. def schrage_przerwania():
  94.     mega_maszyna = []
  95.  
  96.     file_handle = open('data2.txt', 'r')
  97.  
  98.     lines_list = file_handle.readlines()
  99.  
  100.     zadania, maszyna = (int(val) for val in lines_list[0].split())
  101.  
  102.     mega_kursor = [0] * maszyna
  103.  
  104.     dane = [[int(val) for val in line.split()] for line in lines_list[1:]]
  105.  
  106.     for i in range(1, maszyna + 1):
  107.         mini_maszyna = [0] * zadania
  108.  
  109.         j = i
  110.         for i in range(0, zadania):
  111.             mini_maszyna[i] = dane[i][j - 1]
  112.  
  113.         mega_maszyna.append(mini_maszyna)
  114.  
  115.     t = 0
  116.     k = 0
  117.     c_max = 0
  118.     G = [];
  119.     N = list(range(0, zadania))
  120.     lista_pomocnicza = []
  121.     pi = [0] * zadania
  122.     r = mega_maszyna[0]
  123.     p = mega_maszyna[1]
  124.     q = mega_maszyna[2]
  125.  
  126.     r_core = r[::]
  127.     p_core = p[::]
  128.     q_core = q[::]
  129.  
  130.     q[0] = math.inf
  131.     l = 0
  132.  
  133.     # --------------------------DEFINICJE--------------------------#
  134.     q_kopia = q[::]
  135.     Q = []
  136.  
  137.     while ((G != []) or (N != [])):
  138.  
  139.         while ((N != []) and (min(value for value in r if value != None) <= t)):
  140.             e = min(value for value in r if value != None)
  141.             e_arg = r.index(e)
  142.  
  143.             G.append(e_arg)
  144.             N.remove(e_arg)
  145.  
  146.             if q[e_arg] > q[l]:
  147.                 p[l] = t - r[e_arg]
  148.                 t = r[e_arg]
  149.                 if p[l] > 0:
  150.                     G.append(l)
  151.  
  152.             r[e_arg] = None
  153.  
  154.             if q[0] == math.inf:
  155.                 q[0] = q_core[0]
  156.  
  157.         for i in range(0, len(G)):
  158.             x = q[G[i]]
  159.             Q.append(x)
  160.  
  161.         if G == []:
  162.             t = min(value for value in r if value != None)
  163.  
  164.         else:
  165.             e = max(value for value in Q if value != None)
  166.  
  167.             eq = Q.index(e)
  168.             e_arg = G[eq]
  169.  
  170.             l = e_arg
  171.             t = t + p[e_arg]
  172.             c_max = max(c_max, t + q[e_arg])
  173.  
  174.             G.remove(e_arg)
  175.  
  176.         Q = []
  177.         P = mega_maszyna[1]
  178.  
  179.         globals()['c_max'] = c_max
  180.         globals()['pi'] = pi
  181.  
  182.  
  183. # ---------------------  INICJALIZACJA  ---------------------
  184.  
  185.  
  186.  
  187. def Carlier():
  188.  
  189.     UB = 10000000
  190.  
  191.     # ---------------------------  1  ---------------------------
  192.  
  193.     schrage()
  194.     U = c_max
  195.  
  196.     # ---------------------------  2  ---------------------------
  197.  
  198.     if U < UB:
  199.         UB = U
  200.         pi_nowe = pi[::]
  201.  
  202.     # ---------------------------  3  ---------------------------
  203.  
  204.     b = pi[len(pi)-1]
  205.     a = pi[0]
  206.     c = pi[len(pi)-2]
  207.  
  208.     # ---------------------------  4  ---------------------------
  209.     if c == None:
  210.         return
  211.  
  212.     # ---------------------------  5  ---------------------------
  213.  
  214.     r_prim = rnowe[j_arg]
  215.     print(r_prim)
  216.  
  217.     granice = list(range(c+1, b+1))
  218.     #print(granice)
  219.     r_pomoc = []
  220.     q_pomoc = []
  221.     p_pomoc = []
  222.  
  223.     for i in range (c+1,b+1):
  224.  
  225.         r_pomoc.append(rnowe[i])
  226.         q_pomoc.append(qnowe[i])
  227.         p_pomoc.append(pnowe[i])
  228.  
  229.         #print(r_pomoc)
  230.         #print(q_pomoc)
  231.         #print(p_pomoc)
  232.  
  233.     er = min(r_pomoc)
  234.     qu = min(q_pomoc)
  235.     pe = sum(p_pomoc)
  236.  
  237.     print(er, qu, pe)
  238.  
  239.  
  240.  
  241.     # ---------------------------  6  ---------------------------
  242.     r_new = rnowe[::]
  243.     r_new[c] = max(rnowe[c],(er+pe))
  244.  
  245.     # ---------------------------  7  ---------------------------
  246.  
  247.     schrage_przerwania()
  248.     LB = c_max
  249.  
  250.     # ---------------------------  8  ---------------------------
  251.  
  252.     if LB < UB:
  253.  
  254.     # ---------------------------  9  ---------------------------
  255.  
  256.         Carlier()
  257.  
  258.     # ---------------------------  10  ---------------------------
  259.  
  260.     r_new = rnowe[::]
  261.  
  262.     # ---------------------------  11  ---------------------------
  263.  
  264.     q_new = qnowe[::]
  265.     q_new[c] = max(qnowe[c],(qu+pe))
  266.  
  267.     # ---------------------------  12  ---------------------------
  268.  
  269.     schrage_przerwania()
  270.     LB = c_max
  271.  
  272.     # ---------------------------  13  ---------------------------
  273.  
  274.     if LB < UB:
  275.  
  276.     # ---------------------------  14  ---------------------------
  277.  
  278.         Carlier()
  279.  
  280.     # ---------------------------  15  ---------------------------
  281.  
  282.     q_new = qnowe[::]
  283.  
  284.  
  285. Carlier()
  286. #print("Cmax: ", UB)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top