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

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

Go to download

JGraphX Swing Component - Java Graph Visualization Library This is a binary & source redistribution of the original, unmodified JGraphX library originating from: "https://github.com/jgraph/jgraphx/archive/v3.4.1.3.zip". The purpose of this redistribution is to make the library available to other Maven projects.

There is a newer version: 3.4.1.3
Show newest version
package com.mxgraph.generatorfunction;

import com.mxgraph.view.mxCellState;

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

	private double minWeight = 0;

	public mxGeneratorRandomIntFunction(double minWeight, double maxWeight)
	{
		setWeightRange(minWeight, maxWeight);
	};

	public double getCost(mxCellState state)
	{
		//assumed future parameters
		//		mxGraph graph = state.getView().getGraph();
		//		Object cell = state.getCell();

		if (minWeight == maxWeight)
		{
			return minWeight;
		}

		double currValue = minWeight + Math.round((Math.random() * (maxWeight - minWeight)));
		return currValue;
	};

	public double getMaxWeight()
	{
		return maxWeight;
	};

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

	public double getMinWeight()
	{
		return minWeight;
	};
};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy