Advertisement
Guest User

Untitled

a guest
May 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.lang.Integer;
  6. import java.lang.String;
  7. import java.util.*;
  8.  
  9. public class Main {
  10. public static void main(String args[]) throws IOException {
  11. File file = new File("input.txt");
  12. ArrayList<Node> nodes = parseText(file);
  13. //System.out.println(Graph.addEdge(nodes));
  14. }
  15.  
  16. public static ArrayList<Node> parseText(File file) throws IOException {
  17. ArrayList<Node> nodes = new ArrayList<>();
  18.  
  19. BufferedReader br = new BufferedReader(new FileReader(file));
  20. String line;
  21.  
  22. while ((line = br.readLine()) != null) {
  23. String[] words = line.split("\\s+");
  24. ArrayList<Integer> data = new ArrayList<Integer>();
  25. for(int i = 3; i < words.length; i++ )
  26. {
  27. data.add(Integer.parseInt(words[i]));
  28. // System.out.println(data);
  29. }
  30. Node n = new Node(Integer.parseInt(words[0]), Float.parseFloat(words[1]), Float.parseFloat(words[2]), data);
  31. nodes.add(n);
  32. System.out.println(n);
  33. }
  34.  
  35. br.close();
  36.  
  37. return nodes;
  38. }
  39. }
  40.  
  41. class Node {
  42. public int id;
  43. public float x, y;
  44. public boolean isBlack;
  45. public ArrayList<Integer> data;
  46.  
  47. public Node(int id, float x, float y, ArrayList<Integer> data) {
  48. this.id = id;
  49. this.x = x;
  50. this.y = y;
  51. this.data = data;
  52. this.isBlack = id % 2 == 0 ? true : false;
  53. }
  54.  
  55. public String toString() {
  56. String s = "[id:" + this.id + ", x:" + this.x + ", y:" + this.y + ", data:" + this.data + "]";
  57. return s;
  58. }
  59.  
  60. public int getID() {
  61. return this.id;
  62. }
  63. }
  64.  
  65. class Graph {
  66.  
  67. public ArrayList<Double> edges = new ArrayList<>();
  68. public Node n;
  69. public Graph(ArrayList<Node> nodes, ArrayList<Double> edges, Node n) {
  70. this.edges = edges;
  71. }
  72.  
  73. public ArrayList<Double> addEdge(ArrayList<Node> nodes) {
  74. float distx = 0;
  75. float disty = 0;
  76. double distall = 0;
  77. for(int i=0; i< nodes.size(); ++i) {
  78. for (int j=i+1; j<nodes.size(); ++j) {
  79. distx = nodes.get(i).x + nodes.get(j).x;
  80. disty = nodes.get(i).y + nodes.get(j).y;
  81. distall = Math.sqrt(distx*distx + disty*disty);
  82. edges.add(distall);
  83. }
  84. } return edges;
  85. }
  86. public double MDistance(Node node1, Node node2) {
  87. float dx = node1.x - node2.x;
  88. float dy = node1.y - node2.y;
  89. double dsum = Math.sqrt(dx*dx + dy*dy );
  90. return dsum;
  91.  
  92. }
  93. }
  94.  
  95. class Edge {
  96. public ArrayList<Double> edges;
  97. public ArrayList<Node> nodes;
  98. public Edge(ArrayList<Double> edges, ArrayList<Node> nodes) {
  99. this.edges = edges;
  100. this.nodes = nodes;
  101.  
  102.  
  103. System.out.println(Graph.addEdge(nodes));
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement