Package util

Source Code of util.RandomGraphGenerator

package util;

import core.Graphs.Graph;

import java.util.Random;

/**
* Nothing software.
*/
public class RandomGraphGenerator implements GraphGenerator {

    @Override
    public Object generate(int numberOfNodes) {
        int[][] adjacencyMatrix = new int[numberOfNodes][numberOfNodes];
        Random random = new Random();
        for (int i = 0; i < numberOfNodes; i++) {
            for (int j = i; j < numberOfNodes; j++) {
                boolean value = random.nextBoolean();
                if (value) {
                    adjacencyMatrix[i][j] = 1;
                    adjacencyMatrix[j][i] = 1;
                } else {
                    adjacencyMatrix[i][j] = 0;
                    adjacencyMatrix[j][i] = 0;
                }
            }
            adjacencyMatrix[i][i] = 0;
        }

        return new Graph(adjacencyMatrix);
    }
}
TOP

Related Classes of util.RandomGraphGenerator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.