本文整理汇总了Java中org.apache.commons.collections15.Transformer类的典型用法代码示例。如果您正苦于以下问题:Java Transformer类的具体用法?Java Transformer怎么用?Java Transformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transformer类属于org.apache.commons.collections15包,在下文中一共展示了Transformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnreachable
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
@Test
public void testUnreachable() {
Graph<String, MyLink> g = new DirectedOrderedSparseMultigraph<String, MyLink>();
String n1 = new String("S"); // S
g.addVertex(n1);
String n2 = new String("A"); // A
g.addVertex(n2);
String n3 = new String("B"); // B -- not connected
g.addVertex(n3);
g.addEdge(new MyLink(1, "S-A"), n1, n2, EdgeType.DIRECTED); // S - A
Transformer<MyLink, Number> weightTrans = new Transformer<MyLink, Number>() {
@Override
public Number transform(MyLink link) {
return link.getWeight();
}
};
SuurballeTarjan<String, MyLink> testMain = new SuurballeTarjan<String, MyLink>(
g, weightTrans);
assertEquals(null, testMain.getDisjointPaths(n1, n3));
}
示例2: testNoDisjointSolution
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
@Test
public void testNoDisjointSolution() {
Graph<String, MyLink> g = new DirectedOrderedSparseMultigraph<String, MyLink>();
String n1 = new String("A"); // A
g.addVertex(n1);
String n2 = new String("B"); // B
g.addVertex(n2);
g.addEdge(new MyLink(2, "A-B"), n1, n2, EdgeType.DIRECTED);
Transformer<MyLink, Number> weightTrans = new Transformer<MyLink, Number>() {
@Override
public Number transform(MyLink link) {
return link.getWeight();
}
};
SuurballeTarjan<String, MyLink> testMain = new SuurballeTarjan<String, MyLink>(
g, weightTrans);
assertEquals("[[A-B]]", testMain.getDisjointPaths(n1, n2).toString());
}
示例3: getDistance
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
DistanceEntry getDistance(SubstrateNetwork sNetwork, SubstrateNode from,
SubstrateNode to, Transformer<SubstrateLink, Double> transformer) {
if (from.getId() == to.getId()) {
return new DistanceEntry(from, to, new LinkedList<SubstrateLink>(),
0.0);
}
// we need a new instance here because we use other link weights
// every time
MyDijkstraShortestPath<SubstrateNode, SubstrateLink> dijkstra = new MyDijkstraShortestPath<SubstrateNode, SubstrateLink>(
sNetwork, transformer, true);
List<SubstrateLink> path = dijkstra.getPath(from, to);
if (path == null) {
return null;
}
Number distance = dijkstra.getDistance(from, to);
return new DistanceEntry(from, to, path, distance.doubleValue());
}
示例4: findShortestPath
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
public static LinkedList<SubstrateLink> findShortestPath(
SubstrateNetwork sNetwork,
SubstrateNode n1, SubstrateNode n2,
Transformer<SubstrateLink, Double> t) {
if (n1.getId() == n2.getId()) {
return new LinkedList<SubstrateLink>();
}
MyDijkstraShortestPath<SubstrateNode, SubstrateLink> dijkstra =
new MyDijkstraShortestPath<SubstrateNode, SubstrateLink>(
sNetwork, t, true);
LinkedList<SubstrateLink> path = dijkstra.getPath(n1, n2, -1);
return path;
}
示例5: findAllShortestPaths
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
public static Collection<LinkedList<SubstrateLink>> findAllShortestPaths(
SubstrateNetwork sNetwork,
SubstrateNode n,
Transformer<SubstrateLink, Double> t) {
Collection<LinkedList<SubstrateLink>> result = new LinkedList<LinkedList<SubstrateLink>>();
for (SubstrateNode n2 : sNetwork.getVertices()) {
if (n != n2) {
LinkedList<SubstrateLink> current =
findShortestPath(sNetwork, n, n2, t);
if (current != null) {
result.add(current);
}
}
}
return result;
}
示例6: getShortestPathsALinkGoesThrough
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
public static Collection<LinkedList<SubstrateLink>> getShortestPathsALinkGoesThrough(
SubstrateNetwork sNetwork,
SubstrateLink l,
Transformer<SubstrateLink, Double> t) {
Collection<LinkedList<SubstrateLink>> result = new LinkedList<LinkedList<SubstrateLink>>();
Map<SubstrateNode, Collection<LinkedList<SubstrateLink>>> all =
Utils.findAllShortestPaths(sNetwork, t);
for (Entry<SubstrateNode, Collection<LinkedList<SubstrateLink>>> e : all.entrySet()) {
for (LinkedList<SubstrateLink> path : e.getValue()) {
if (path.contains(l)) {
result.add(path);
break;
}
}
}
return result;
}
示例7: setPrototypePreview
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
/**
* This method takes the GraphPrototype class name as string and creates a graph of the prototype and shows a preview in the visualizationViewer
* @param graphPrototype
*/
private void setPrototypePreview() {
String componentName = this.localComponentTypeListElement.getComponentName();
// --- Create the graph of the NetworkComponent -------------
this.localNetworkModel = NetworkComponentFactory.getNetworkModel4NetworkComponent(this.graphController.getNetworkModel().getGeneralGraphSettings4MAS(), componentName, this.getVisualizationViewer().getSize());
this.localGraphElementPrototype = NetworkComponentFactory.getGraphElementPrototypeOfLastNetworkComponent();
if (this.localNetworkModel!=null && this.localGraphElementPrototype!=null) {
// --- Set the graph to the layout ----------------------
Layout<GraphNode, GraphEdge> layout = new StaticLayout<GraphNode, GraphEdge>(this.localNetworkModel.getGraph());
layout.setInitializer(new Transformer<GraphNode, Point2D>() {
public Point2D transform(GraphNode node) {
return node.getPosition();
}
});
this.getVisualizationViewer().setGraphLayout(layout);
this.getVisualizationViewer().repaint();
// --- Pick first GraphNode --------------------
this.pickFirstGraphNode();
this.setSelectedGraphNode();
}
}
示例8: getPanel
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
public static GraphVisualizationPanel<MarkovVertex, MarkovEdge> getPanel(
Graph<MarkovVertex, MarkovEdge> test_graph) {
GraphVisualizationPanel<MarkovVertex, MarkovEdge> graph_panel = GraphVisualizationPanel
.factory(test_graph);
Transformer<MarkovVertex, Paint> transformer = new VertexTransformer<MarkovVertex, Paint>();
graph_panel.getRenderContext().setVertexFillPaintTransformer(
transformer);
graph_panel.getRenderContext().setEdgeLabelTransformer(
new ToStringLabeller<MarkovEdge>());
PluggableGraphMouse gm = new PluggableGraphMouse();
gm.add(new PopupMousePlugin<MarkovVertex, MarkovEdge>());
gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON1_MASK));
graph_panel.setGraphMouse(gm);
Transformer<MarkovVertex, String> labelTransform = new VertexLabelTransformer<MarkovVertex, String>();
graph_panel.getRenderContext()
.setVertexLabelTransformer(labelTransform);
return graph_panel;
}
示例9: main
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
/**
* Main.
*
* @param args
* command line arguments
*/
public static void main(String[] args) {
TestExample example = new TestExample();
Term bdd = example.get();
Transformer<String, ReliabilityFunction> exponentialTransformer = new TestExponentialTransformer();
Transformer<String, ReliabilityFunction> weibullTransformer = new TestWeibullTransformer();
BDDProviderFactory bddProviderFactory = new JBDDProviderFactory();
BDDProvider<String> bddProvider = bddProviderFactory.getProvider();
BDDTTRF<String> transformer = new BDDTTRF<>(bddProvider);
ReliabilityFunction exponentialDistribution = transformer.convert(bdd, exponentialTransformer);
ReliabilityFunction weibullDistribution = transformer.convert(bdd, weibullTransformer);
Map<String, ReliabilityFunction> reliabilityFunction = new HashMap<>();
reliabilityFunction.put("Exponential", exponentialDistribution);
reliabilityFunction.put("Weibull", weibullDistribution);
ReliabilityViewer.view("JReliability Viewer", reliabilityFunction);
}
示例10: calculate
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
/**
* Calculates the top event for the values given by the functionTransformer.
*
* @param transformer
* the transformer from the variables to the values
* @return the top event
*/
public double calculate(Transformer<T, Double> transformer) {
for (Entry<T, Var> entry : variables.entrySet()) {
T t = entry.getKey();
Var var = entry.getValue();
double value = transformer.transform(t);
var.setValue(value);
}
for (VarNode node : nodes) {
double r = node.getVar().getValue();
double low = node.getLo().getValue();
double high = node.getHi().getValue();
// Shannon decomposition
double y = r * high + (1 - r) * low;
node.setValue(y);
}
return root.getValue();
}
示例11: getY
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
@Override
public double getY(final double x) {
final Transformer<T, Double> t = new Transformer<T, Double>() {
/**
* Default {@link Transformer}.
*
* @param a
* parameter a
* @return the double value of a
*/
@Override
public Double transform(T a) {
return functionTransformer.transform(a).getY(x);
}
};
return topEvent.calculate(t);
}
示例12: calculateTop
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
/**
* Calculates the top event of the {@link BDD} based on a functionTransformer that delivers for each variable
* {@code T} a double value.
*
* @param <T>
* the type of variable
* @param bdd
* the bdd
* @param transformer
* the transformer that returns a double value for each variable
* @return the top event of the bdd
*/
public static <T> double calculateTop(BDD<T> bdd, Transformer<T, Double> transformer) {
if (bdd.isOne()) {
return 1.0;
}
if (bdd.isZero()) {
return 0.0;
}
Set<BDD<T>> upSort = new LinkedHashSet<>();
traverseBDD(bdd, upSort);
double top = evaluate(bdd, transformer, upSort);
for (BDD<T> ups : upSort) {
ups.free();
}
return top;
}
示例13: simulateTimeToFailure
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
/**
* Performs a single simulation run to gather one time-to-failure.
*
* @param bdd
* the given bdd
* @param functionTransformer
* the element to reliability function transformer
* @return a single time-to-failure
*/
protected double simulateTimeToFailure(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
double time = 0;
BDD<T> myBDD = bdd.copy();
Set<Failure<T>> failures = getFailures(bdd, functionTransformer);
for (Failure<T> failure : failures) {
BDD<T> objectVariable = provider.get(failure.getObject());
myBDD.restrictWith(objectVariable.not());
if (myBDD.isZero()) {
time = failure.getTime();
break;
}
}
return time;
}
示例14: testCalculate
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
@Test
public void testCalculate() {
BDD<String> a = provider.get("a");
BDD<String> b = provider.get("b");
BDD<String> and = a.and(b);
BDDTopEvent<String> event = new BDDTopEvent<>(and);
double result = event.calculate(new Transformer<String, Double>() {
@Override
public Double transform(String input) {
return 0.5;
}
});
Assert.assertEquals(0.25, result, 0.000001);
}
示例15: testCalculateSeriesParallel
import org.apache.commons.collections15.Transformer; //导入依赖的package包/类
@Test
public void testCalculateSeriesParallel() {
BDD<String> a = provider.get("a");
BDD<String> b = provider.get("b");
BDD<String> bdd = a.or(b);
BDD<String> c = provider.get("c");
bdd = bdd.and(c);
BDDTopEvent<String> event = new BDDTopEvent<>(bdd);
double result = event.calculate(new Transformer<String, Double>() {
@Override
public Double transform(String input) {
return 0.9;
}
});
Assert.assertEquals(0.891, result, 0.000001);
}