Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Random;
- import java.util.concurrent.ThreadLocalRandom;
- public class Main {
- /**Рыбаков
- Исходные данные:
- В1 = 3, А = 2, B = 21, C = 15, D=4
- K = a mod 5 = 2 mod 5 = 2
- Если К = 2 то N = 14*/
- public static void main(String[] args) {
- int a = 2;
- int b = 21;
- int c = 15;
- int d = 4;
- int n = 14;
- Graph g = generateGraph(n,a,b,c,d);
- for (Vertex vertice : g.vertices) {
- System.out.println("Ver "+ vertice.position);
- }
- for (Edge edge : g.edges) {
- System.out.println("Edge "+edge.vertices[0].position+"->"+ edge.vertices[1].position+" weight "+edge.weight);
- }
- }
- public static boolean edgeCondition(int i,int j,int a,int b,int c,int d){
- return ((i*a+b*j)/c)%d <=1;
- }
- public static int randomWeight(int a, int c){
- return ThreadLocalRandom.current().nextInt(a, a + c + 1);
- }
- public static Graph generateGraph(int n,int a,int b,int c,int d){
- List<Vertex> vertices = new LinkedList<>();
- List<Edge> edges = new LinkedList<>();
- for (int i = 0; i < 14; i++) {
- vertices.add(new Vertex(i));
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (edgeCondition(i,j,a,b,c,d)){
- edges.add(new Edge(
- randomWeight(a,c),
- new Vertex[]{vertices.get(i),vertices.get(j)}));
- }
- }
- }
- return new Graph(vertices,edges);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement