<commit_before>package graph.util;

import graph.Graph;
import graph.RegularGraph;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * Created by <NAME> on 07.03.17.
 */
public class D3RegularGraphGenerator extends RegularGraphGenerator {

    /**
     *
     * @param verticesNumber number of vertices
     * @param chromaticNumber chromatic number (if not 2 or 3 then random)
     * @return graph with given parameters
     * @throws IllegalArgumentException if graph from given parameters cannot be constructed
     */
    public <G extends RegularGraph> G getRandomGraph(Class<G> clazz, int verticesNumber, int chromaticNumber) throws IllegalArgumentException {
        G g;

        switch (chromaticNumber) {
            case 2:
                return getRandomBipartiteGraph(clazz, 3, verticesNumber);
            case 3:
                g = getRandomGraph(clazz, 3, verticesNumber);
                LinkedList<LinkedList<Integer>> partitions  = new LinkedList<>();
                partitions.push(new LinkedList<>());
                partitions.push(new LinkedList<>());
                if (isBipartite(g, partitions)) {
                    makeTripartite(g, partitions);
                }
                return g;
            default:
                return getRandomGraph(clazz, 3, verticesNumber);
        }
    }

    private boolean isBipartite(Graph g, LinkedList<LinkedList<Integer>> partitions) {
        int[] verticesColors = new int[g.getVertices()];
        for (int i = 0; i < g.getVertices(); i++) {
            verticesColors[i] = -1;
        }

        verticesColors[0] = 1;
        partitions.get(verticesColors[0]).push(0);
<commit_msg>Change getRandomGraph method.<commit_after>package graph.util;

import graph.Graph;
import graph.RegularGraph;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * Created by <NAME> on 07.03.17.
 */
public class D3RegularGraphGenerator extends RegularGraphGenerator {

    /**
     *
     * @param verticesNumber number of vertices
     * @param chromaticNumber chromatic number (if not 2 or 3 then random)
     * @return graph with given parameters
     * @throws IllegalArgumentException if graph from given parameters cannot be constructed
     */

    public <G extends Graph> G getRandomGraph(Class<G> clazz, int verticesNumber, int chromaticNumber) throws IllegalArgumentException {
        G g;

        switch (chromaticNumber) {
            case 2:
                return BipartiteRegularGraphGenerator.getInstance().getRandomGraph(clazz, 3, verticesNumber);
            case 3:
                g = getRandomGraph(clazz, 3, verticesNumber);
                LinkedList<LinkedList<Integer>> partitions  = new LinkedList<>();
                partitions.push(new LinkedList<>());
                partitions.push(new LinkedList<>());
                if (isBipartite(g, partitions)) {
                    makeTripartite(g, partitions);
                }
                return g;
            default:
                return getRandomGraph(clazz, 3, verticesNumber);
        }
    }

    private boolean isBipartite(Graph g, LinkedList<LinkedList<Integer>> partitions) {
        int[] verticesColors = new int[g.getVertices()];
        for (int i = 0; i < g.getVertices(); i++) {
            verticesColors[i] = -1;
        }

        verticesColors[0] = 1;
        partitions.get(verticesColors[0]).push(0);

{'fraction_non_alphanumeric': 0.0979081929110982, 'fraction_numerical': 0.011621150493898896, 'mean_word_length': 2.378802747791953, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578993', 'n_tokens_mistral': 962, 'n_tokens_neox': 903, 'n_words': 252}