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

com.mxgraph.generatorfunction.mxGeneratorRandomFunction Maven / Gradle / Ivy

Go to download

This project contains the apt processor that implements all the checks enumerated in @Verify. It is a self contained, and shaded jar.

The newest version!
package com.mxgraph.generatorfunction;

import com.mxgraph.view.mxCellState;

/**
 * @author Mate
 * A generator random cost function
 * It will generate random (type "double") edge weights in the range of (minWeight, maxWeight) and rounds the values to roundToDecimals
 */
public class mxGeneratorRandomFunction extends mxGeneratorFunction
{
	private double maxWeight = 1;

	private double minWeight = 0;

	private int roundToDecimals = 2;

	public mxGeneratorRandomFunction(double minWeight, double maxWeight, int roundToDecimals)
	{
		setWeightRange(minWeight, maxWeight);
		setRoundToDecimals(roundToDecimals);
	};

	public double getCost(mxCellState state)
	{
		Double edgeWeight = null;

		edgeWeight = Math.random() * (maxWeight - minWeight) + minWeight;
		edgeWeight = (double) Math.round(edgeWeight * Math.pow(10, getRoundToDecimals())) / Math.pow(10, getRoundToDecimals());

		return edgeWeight;
	};

	public double getMaxWeight()
	{
		return maxWeight;
	};

	public void setWeightRange(double minWeight, double maxWeight)
	{
		this.maxWeight = Math.max(minWeight, maxWeight);
		this.minWeight = Math.min(minWeight, maxWeight);
	};

	public double getMinWeight()
	{
		return minWeight;
	};

	public int getRoundToDecimals()
	{
		return roundToDecimals;
	};

	public void setRoundToDecimals(int roundToDecimals)
	{
		this.roundToDecimals = roundToDecimals;
	};
};




© 2015 - 2025 Weber Informatics LLC | Privacy Policy