<repo_name>xShadov/NetworkConnectivity<file_sep>/src/main/java/com/shadov/networkconnectivity/task2/CustomEdge.java
package com.shadov.networkconnectivity.task2;

import org.jgrapht.graph.DefaultEdge;

public class CustomEdge extends DefaultEdge {

	private final int maxBandwidth;
	private int bandwidth = 0;

	public CustomEdge(int maxBandwidth) {
		this.maxBandwidth = maxBandwidth;
	}

	public int getMaxBandwidth() {
		return maxBandwidth;
	}

	public int getBandwidth() {
		return bandwidth;
	}

	public void setBandwidth(int bandwidth) {
		this.bandwidth = bandwidth;
	}

	public String toString() {
		return getSource() + " -> " + getTarget() + ": " + bandwidth;
	}
}
<file_sep>/src/main/java/com/shadov/networkconnectivity/task1/SubtaskC.java
package com.shadov.networkconnectivity.task1;

import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.SimpleWeightedGraph;

public class SubtaskC extends SubtaskB {
	public SimpleWeightedGraph<Integer, DefaultWeightedEdge> createGraph() {
		super.createGraph();
		graph.setEdgeWeight(graph.addEdge(1, 10), 0.8);
		graph.setEdgeWeight(graph.addEdge(5, 15), 0.7);
		return graph;
	}

	@Override
	public String toString() {
		return "Graph-C";
	}
}
<file_sep>/src/main/java/com/shadov/networkconnectivity/task1/Task1.java
package com.shadov.networkconnectivity.task1;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Task1 {
	public static final int MONTE_CARLO_ATTEMPTS = 10000;
	public static final boolean LOG = false;

	public void start() {
		List<GraphFactory> graphs = new ArrayList<GraphFactory>();
		graphs.add(new SubtaskA());
		graphs.add(new SubtaskB());
		graphs.add(new SubtaskC());

		ExecutorService executor = Executors.newFixedThreadPool(4);
		List<Future<String>> list = new ArrayList<Future<String>>();

		for (final GraphFactory graphFactory : graphs) {
			Future<String> futureString = executor.submit(new TestingTaskABC(graphFactory));
			list.add(futureString);
		}

		Future<String> futureString = executor.submit(new TestingTaskD(new SubtaskD()));
		list.add(futureString);

		for (Future<String> string : list) {
			try {
				String futured = string.get();
				System.out.println(futured);
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		}

		executor.shutdown();
	}
}
<file_sep>/src/main/java/com/shadov/networkconnectivity/App.java
package com.shadov.networkconnectivity;

import com.shadov.networkconnectivity.task1.Task1;
import com.shadov.networkconnectivity.task2.Task2;

public class App {
	private static final String LOCATION = "exampleGraphs\\example1";

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in))
		{
			switch (scanner.nexInt()) {
				case 1:
					new Task1().start();
					break;
				case 2:
					new Task2().start(LOCATION);
					break;
				default:
					System.err.println("Wrong task number");
			}
		}
	}
}
<file_sep>/src/main/java/com/shadov/networkconnectivity/task2/GraphData.java
package com.shadov.networkconnectivity.task2;

import org.jgrapht.graph.SimpleGraph;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class GraphData {

	private SimpleGraph<Integer, CustomEdge> graph;
	private int[][] flows;
	private double reliability;
	private double maxDelay;
	private final double size = 65535.0;
	private int attempts;

	public GraphData(String fileLocation) throws IOException {

		String line;
		File graphFile = new File(fileLocation + File.separator + "graph.txt");
		try (BufferedReader brGraph = new BufferedReader(new FileReader(graphFile))) {
			String[] splitLine = brGraph.readLine().split(" ");

			reliability = Double.parseDouble(splitLine[0]);
			maxDelay = Double.parseDouble(splitLine[1]);
			attempts = Integer.parseInt(splitLine[2]);

			graph = new SimpleGraph<>(CustomEdge.class);

			while ((line = brGraph.readLine()) != null && (splitLine = line.split(" ")).length == 3) {

				int v1 = Integer.parseInt(splitLine[0]);
				int v2 = Integer.parseInt(splitLine[1]);
				int edgeBandwidth = Integer.parseInt(splitLine[2]);

				graph.addVertex(v1);
				graph.addVertex(v2);
				graph.addEdge(v1, v2, new CustomEdge(edgeBandwidth));

			}
		}

		int graphSize = graph.vertexSet().size();
		flows = new int[graphSize][graphSize];

		graphFile = new File(fileLocation + File.separator + "transfers.txt");

		try (BufferedReader brGraph = new BufferedReader(new FileReader(graphFile))) {
			String[] splitLine;
			while ((line = brGraph.readLine()) != null && (splitLine = line.split(" ")).length == 3) {
				int source = Integer.parseInt(splitLine[0]) - 1;
				int destination = Integer.parseInt(splitLine[1]) - 1;
				int quantity = Integer.parseInt(splitLine[2]);

				flows[source][destination] = quantity;
			}
		}
	}

	public SimpleGraph<Integer, CustomEdge> getGraph() {
		return graph;
	}

	public int[][] getFlows() {
		return flows;
	}

	public double getReliability() {
		return reliability;
	}

	public double getMaxDelay() {
		return maxDelay;
	}

	public double getSize() {
		return size;
	}

	public int getAttempts() {
		return attempts;
	}
}