daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. end
  2.  
  3. for i = 0:n-1
  4.     for j = i+1:n
  5.         costmatrix[i+1, j] = f[i+1] + c[i+1]*Dmatrix[i+1,j]
  6.     end
  7. end
  8.  
  9. ########################Variables
  10.  
  11. x = [0, 0, 0, 0]
  12. y = [0, 0, 0, 0]
  13. current = 1
  14. optimale = zeros(Int32, n)
  15. for i = 1:n
  16.     optimale[i] = -1
  17. end
  18.  
  19. ########################Calculations functions
  20.  
  21. function foo(costs, size)
  22.     if(size == 1)
  23.         return costs[1,1]
  24.     else
  25.         minimal = 9999999
  26.         for i = 1:size
  27.             newmatrix = zeros(Int32, size-i, size-i)
  28.             for j = 1:size-i
  29.                 for k = 1:size-i
  30.                     a = i+j
  31.                     b = i+k
  32.                     newmatrix[j,k] = costs[a, b]
  33.                 end
  34.             end
  35.             if(size-i == 0)
  36.                 if(minimal > costs[1,i])
  37.                     minimal = costs[1,i]
  38.                 end
  39.             else
  40.                 if(minimal > costs[1,i] + foo(newmatrix, size-i))
  41.                     minimal = costs[1,i] + foo(newmatrix, size-i)
  42.                 end
  43.             end
  44.         end
  45.         return minimal
  46.     end
  47. end
  48.  
  49. function getSumOfPath(matrix, size, path)
  50.     sum = 0
  51.     i = 2
  52.     sum = matrix[1, path[1]]
  53.     while path[i] != -1 && i < size
  54.         sum = sum + matrix[i+1, path[i]]
  55.         i = i + 1
  56.     end
  57.     return sum
  58. end
  59.  
  60. function getPathFromCost(targetedCost, costs, size)
  61.     testedPath = zeros(Int32, n)
  62.     correctPath = zeros(Int32, n)
  63.     for l = 1:size
  64.         correctPath[l] = -1
  65.     end
  66.     for i = 1:size
  67.         for l = 1:size
  68.             testedPath[i] = -1
  69.         end
  70.         for j = 1:size-i
  71.             testedPath[j] = i+j
  72.             println(testedPath[j])
  73.         end
  74.         if(getSumOfPath(costs, size, testedPath) == targetedCost)
  75.             println(getSumOfPath(costs, size, testedPath))
  76.             correctPath = testedPath
  77.         end
  78.     end
  79.     return correctPath
  80. end
  81.  
  82. ########################Calculate and print results
  83.  
  84. solveTime = @elapsed (minCost = foo(costmatrix, n))
  85.  
  86. lolPath = [2, 4, -1, -1]
  87. lolSize = 4
  88. getPathFromCost(minCost, costmatrix, n)
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