use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class PreferentialAttachmentGraphBuilderPlugin method updateParameters.
@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
final List<String> nAttributes = new ArrayList<>();
final List<String> tAttributes = new ArrayList<>();
final List<String> nChoices = new ArrayList<>();
final List<String> tChoices = new ArrayList<>();
if (graph != null) {
final Set<Class<? extends SchemaConcept>> concepts = graph.getSchema().getFactory().getRegisteredConcepts();
final Collection<SchemaVertexType> nodeTypes = SchemaVertexTypeUtilities.getTypes(concepts);
for (final SchemaVertexType type : nodeTypes) {
nAttributes.add(type.getName());
}
nAttributes.sort(String::compareTo);
final Collection<SchemaTransactionType> transactionTypes = SchemaTransactionTypeUtilities.getTypes(concepts);
for (final SchemaTransactionType type : transactionTypes) {
tAttributes.add(type.getName());
}
tAttributes.sort(String::compareTo);
nChoices.add(nAttributes.get(0));
tChoices.add(tAttributes.get(0));
}
if (parameters != null && parameters.getParameters() != null) {
// NODE_TYPES_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(NODE_TYPES_PARAMETER_ID);
// TRANSACTION_TYPES_PARAMETER will always be of type MultiChoiceParameter
@SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
MultiChoiceParameterType.setOptions(nAttribute, nAttributes);
MultiChoiceParameterType.setOptions(tAttribute, tAttributes);
MultiChoiceParameterType.setChoices(nAttribute, nChoices);
MultiChoiceParameterType.setChoices(tAttribute, tChoices);
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class PreferentialAttachmentGraphBuilderPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
interaction.setProgress(0, 0, "Building...", true);
final Map<String, PluginParameter<?>> params = parameters.getParameters();
final int n = params.get(N_PARAMETER_ID).getIntegerValue();
final int m = params.get(M_PARAMETER_ID).getIntegerValue();
final boolean randomWeights = params.get(RANDOM_WEIGHTS_PARAMETER_ID).getBooleanValue();
final List<String> nodeTypes = params.get(NODE_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
final List<String> transactionTypes = params.get(TRANSACTION_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
assert m >= 1 && m < n : String.format("[Number of edges to attach '%s' must be at least 1 and less than the number of nodes '%s']", m, n);
// Random countries to put in the graph
final List<String> countries = new ArrayList<>();
countries.add("Australia");
countries.add("Brazil");
countries.add("China");
countries.add("France");
countries.add("Japan");
countries.add("New Zealand");
countries.add("South Africa");
countries.add("United Arab Emirates");
countries.add("United Kingdom");
countries.add("United States");
final int vxIdentifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
final int vxTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int vxIsGoodAttr = graph.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "isGood", null, false, null);
final int vxCountryAttr = SpatialConcept.VertexAttribute.COUNTRY.ensure(graph);
final int vxPinnedAttr = VisualConcept.VertexAttribute.PINNED.ensure(graph);
final int txIdAttr = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
final int txTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
final int txDateTimeAttr = TemporalConcept.TransactionAttribute.DATETIME.ensure(graph);
final int[] startVxIds = new int[m];
final VertexDecorators decorators;
decorators = new VertexDecorators(graph.getAttributeName(vxCountryAttr), graph.getAttributeName(vxPinnedAttr), null, graph.getAttributeName(vxIsGoodAttr));
final int decoratorsAttr = VisualConcept.GraphAttribute.DECORATORS.ensure(graph);
graph.setObjectValue(decoratorsAttr, 0, decorators);
int vx = 0;
while (vx < m) {
final int vxId = graph.addVertex();
final String label = "Node_" + vxId;
graph.setStringValue(vxIdentifierAttr, vxId, label);
graph.setStringValue(vxTypeAttr, vxId, nodeTypes.get(r.nextInt(nodeTypes.size())));
graph.setBooleanValue(vxIsGoodAttr, vxId, r.nextInt(10) == 0);
graph.setStringValue(vxCountryAttr, vxId, countries.get(r.nextInt(countries.size())));
if (graph.getSchema() != null) {
graph.getSchema().completeVertex(graph, vxId);
}
startVxIds[vx] = vxId;
vx++;
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
// Create transactions between the nodes.
final Date d = new Date();
final int fourDays = 4 * 24 * 60 * 60 * 1000;
Set<Integer> destinations = Arrays.stream(startVxIds).boxed().collect(Collectors.toSet());
final List<Integer> repeats = new ArrayList<>();
while (vx < n) {
final int vxId = graph.addVertex();
final String label = "Node_" + vxId;
graph.setStringValue(vxIdentifierAttr, vxId, label);
graph.setStringValue(vxTypeAttr, vxId, nodeTypes.get(r.nextInt(nodeTypes.size())));
graph.setBooleanValue(vxIsGoodAttr, vxId, r.nextInt(10) == 0);
graph.setStringValue(vxCountryAttr, vxId, countries.get(r.nextInt(countries.size())));
if (graph.getSchema() != null) {
graph.getSchema().completeVertex(graph, vxId);
}
final int reciprocity = r.nextInt(3);
for (final int destination : destinations) {
int numTimes = 1;
if (randomWeights) {
numTimes = r.nextInt(1 + r.nextInt(100));
}
for (int i = 0; i < numTimes; i++) {
int sxId = vxId;
int dxId = destination;
if (randomWeights) {
switch(reciprocity) {
case 0:
final boolean random0 = r.nextBoolean();
if (random0) {
sxId = destination;
dxId = vxId;
}
break;
case 1:
final int random1 = r.nextInt(5);
if (random1 == 0) {
sxId = destination;
dxId = vxId;
}
break;
default:
final int randomDefault = r.nextInt(5);
if (randomDefault != 0) {
sxId = destination;
dxId = vxId;
}
break;
}
}
final int e = graph.addTransaction(sxId, dxId, true);
graph.setLongValue(txDateTimeAttr, e, d.getTime() - r.nextInt(fourDays));
graph.setStringValue(txTypeAttr, e, transactionTypes.get(r.nextInt(transactionTypes.size())));
graph.setIntValue(txIdAttr, e, e);
if (graph.getSchema() != null) {
graph.getSchema().completeTransaction(graph, e);
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
repeats.add(vxId);
repeats.add(destination);
}
destinations = generateDestinations(repeats, m, r);
vx++;
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
try {
if (n < 10000) {
// Do a trees layout.
PluginExecutor.startWith(ArrangementPluginRegistry.TREES).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
} else {
// Do a grid layout.
PluginExecutor.startWith(ArrangementPluginRegistry.GRID_COMPOSITE).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
}
} catch (final PluginException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
interaction.setProgress(1, 0, "Completed successfully", true);
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class CompleteGraphBuilderPluginNGTest method testUpdateParametersNullGraph.
/**
* Test of updateParameters method, of class CompleteGraphBuilderPlugin. Null graph
*/
@Test
public void testUpdateParametersNullGraph() {
System.out.println("updateParametersNullGraph");
final CompleteGraphBuilderPlugin instance = new CompleteGraphBuilderPlugin();
final PluginParameters params = instance.createParameters();
final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
instance.updateParameters(null, params);
assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
}
Aggregations