com.mxgraph.generatorfunction.mxGeneratorRandomIntFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgraphx Show documentation
Show all versions of jgraphx Show documentation
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.
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;
};
};