All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opt4j.tutorial.salesman.SalesmanProblem Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
package org.opt4j.tutorial.salesman;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import org.opt4j.core.start.Constant;

import com.google.inject.Inject;

public class SalesmanProblem {

	protected Set cities = new HashSet();

	public class City {
		protected final double x;
		protected final double y;

		public City(double x, double y) {
			this.x = x;
			this.y = y;
		}

		public double getX() {
			return x;
		}

		public double getY() {
			return y;
		}
	}

	@Inject
	public SalesmanProblem(@Constant(value = "size") int size) {
		Random random = new Random(0);

		for (int i = 0; i < size; i++) {
			final double x = random.nextDouble() * 100;
			final double y = random.nextDouble() * 100;
			final City city = new City(x, y);

			cities.add(city);
		}
	}

	public Set getCities() {
		return cities;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy