Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mrozwadowski.tsp;
- import com.mrozwadowski.tsp.aco.ACParams;
- import java.io.*;
- import java.util.Scanner;
- /**
- *
- * @author Jakub
- */
- public class Tester {
- Graph graph;
- PrintStream out;
- Scanner scanner;
- double values[] = new double[6];
- int iters = 50;
- static int loop = 5;
- static double alpha[] = {1.0, 2.0};
- static double beta[] = {2.0, 6.0};
- static double tau0[] = {0.1, 1.0};
- static double rho[] = {0.5, 0.8};
- static double Q[] = {100, 200};
- static double ants[] = {0.2, 0.5};
- double a1, b1, t1, r1, q1, an1;
- double[] makeValues(double a, double b, double t, double r, double q, double an){
- double vals[] = new double[6];
- vals[0] = a;
- vals[1] = b;
- vals[2] = t;
- vals[3] = r;
- vals[4] = q;
- vals[5] = an;
- return vals;
- }
- Tester(InputStream in, PrintStream out) {
- scanner = new Scanner(in);
- this.out = out;
- }
- void readNumCities() throws Exception {
- int numCities = scanner.nextInt();
- if (numCities < 2) {
- throw new Exception("Należy podać co najmniej dwa punkty!");
- }
- graph = new Graph();
- }
- void readCities() {
- while (scanner.hasNextInt()) {
- graph.addCity(new City(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()));
- }
- }
- void findAndPrintResults() {
- ACParams colony = new ACParams(graph, values, iters);
- Solution solution = colony.findPath();
- System.out.println("Result: "+solution.getLength());
- out.println(colony.getNumCities());
- for (City city: solution.getCities()) {
- out.println(city.getNum()+" "+city.getX()+" "+city.getY());
- }
- }
- public static void main(String[] args) throws Exception {
- /*
- If you run the program with an argument, the instance will be loaded
- from a file in `instances` directory and a solution will be written
- to `solutions`. Otherwise, standard I/O will be used.
- */
- InputStream in = System.in;
- PrintStream out = System.out;
- if (args.length == 1) {
- String file = args[0];
- in = new FileInputStream("instances/"+file);
- out = new PrintStream("solutions/"+file);
- }
- Tester app = new Tester(in, out);
- app.readNumCities();
- app.readCities();
- for (double a = alpha[0]; a <= alpha[1]; a += (alpha[1]-alpha[0])/loop){
- for (double b = beta[0]; b <= beta[1]; b += (beta[1]-beta[0]/loop)){
- for (double t = tau0[0]; t <= tau0[1]; t += (tau0[1]-tau0[0]/loop)){
- for (double r = rho[0]; r <= rho[1]; r += (rho[1]-rho[0]/loop)){
- for (double q = Q[0]; q <= Q[1]; q += (Q[1]-Q[0]/loop)){
- for (double an = ants[0]; an <= ants[1]; an += (ants[1]-ants[0]/loop)){
- //values[] = {a, b, t, r, q, an};
- //values[] = makeValues(a,b,t,r,q,an);
- app.findAndPrintResults();
- }
- }
- }
- }
- }
- }
- //app.readNumCities();
- //app.readCities();
- //app.findAndPrintResults();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement