Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public IncidenceMatrix toIncidenceMatrix(){
  2.  
  3. ArrayList<ArrayList<Integer>> incidenceMatrix = new ArrayList<>(matrix.size());
  4. System.out.println(matrix.size() + " " + matrix.get(0).size() );
  5.  
  6. for (int i = 0; i < matrix.size(); i++) {
  7. ArrayList<Integer> row = new ArrayList<>();
  8.  
  9. for (int j = 0; j < getIncidenceRowSize() ; j++) {
  10. row.add(0);
  11. }
  12. incidenceMatrix.add(row);
  13.  
  14. }
  15.  
  16. int count = 0;
  17. int newCount = 0;
  18.  
  19. for (int i = 0; i < matrix.size(); i++){
  20. for (int j = i; j < matrix.size(); j++){
  21.  
  22.  
  23. if(matrix.get(i).get(j) == 2){
  24. System.out.println(i + " " + j);
  25. incidenceMatrix.get(i).set(count, 2);
  26. newCount++;
  27. count = newCount;
  28. continue;
  29. }
  30.  
  31. if(matrix.get(i).get(j) != 0){
  32.  
  33. newCount += matrix.get(i).get(j);
  34.  
  35. for(int k = count; k < newCount; k++){
  36.  
  37. incidenceMatrix.get(i).set(k, 1);
  38.  
  39. incidenceMatrix.get(j).set(k, 1);
  40.  
  41. }
  42.  
  43. count = newCount;
  44. }
  45.  
  46.  
  47. }
  48. }
  49.  
  50. IncidenceMatrix returnIncidenceMatrix = new IncidenceMatrix(incidenceMatrix);
  51.  
  52. return returnIncidenceMatrix;
  53. }
  54.  
  55. private int getIncidenceRowSize(){
  56.  
  57. int incidenceRowSize = 0;
  58.  
  59. for (int i = 0; i < matrix.size(); i++){
  60. for (int j = i; j < matrix.size() - 1; j++){
  61.  
  62. if(matrix.get(i).get(j) == 2){
  63. incidenceRowSize++;
  64. continue;
  65. }
  66.  
  67. if(matrix.get(i).get(j) != 0){
  68. incidenceRowSize += matrix.get(i).get(j);
  69. }
  70. }
  71. }
  72.  
  73. return incidenceRowSize;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement