protected ArrayList<IWare> findWaresOfInterest(List<Pair<IWare, Number>> sortedNeeds) { ArrayList<IWare> waresOfInterest = new ArrayList<>(); // wares to be delivered to hometown for (Pair<IWare, Number> need : sortedNeeds) { if (need.getValue().doubleValue() < 0 || waresOfInterest.isEmpty()) { waresOfInterest.add(need.getKey()); } else if (waresOfInterest.size() < 2) { // Have at least 2 entries in the list waresOfInterest.add(need.getKey()); } else { break; // list is sorted by value increasing order } } return waresOfInterest; }
public void clear() { meshAndMaterialToRender.set(new Pair<>(null, null)); }
if (!roleTypeId.isEmpty()) { RoleType role = graph.getRoleType(roleTypeId); roleVarTypeMap.put(role, new Pair<>(var, type)); allocatedVars.add(var); allocatedRoles.add(role); roleVarTypeMap.put(role, new Pair<>(var, type)); allocatedVars.add(var); allocatedRoles.add(role); String var = varsToAllocate.iterator().next(); Type type = varTypeMap.get(var); roleVarTypeMap.put(role, new Pair<>(var, type)); roleVarTypeMap.forEach( (r, tp) -> roleMap.put(tp.getKey(), r.getId())); getVarNames().stream() .filter(var -> !roleMap.containsKey(var))
/** * Load a 3D file. * * @param fileUrl The url of the 3D file to load * @param asPolygonMesh When true load as a PolygonMesh if the loader supports * @return The loaded Node which could be a MeshView or a Group * @throws IOException if issue loading file */ public static Node load(String fileUrl, boolean asPolygonMesh) throws IOException { return loadIncludingAnimation(fileUrl,asPolygonMesh).getKey(); }
/** * Check if the <code>ware</code> is needed in a city. * @param knowledge of the city that should be checked. * @param ware for which should be checked. * @return true if there is not much of the ware around. */ public boolean isNeeded(ICityProductionConsumptionKnowledge knowledge, IWare ware) { List<Pair<IWare, Number>> needs = getMostNeededWares(knowledge); for (Pair<IWare, Number> need : needs) { if (need.getKey().equals(ware) && need.getValue().intValue() < 10) { return true; } else if (need.getKey().equals(ware) || need.getValue().intValue() > 10) { return false; } } return false; }
/** * Instantiate a new service simulator compatible to the given config pair. * * @return the simulator * @throws InstantiationException is thrown if any error occurs during the instantiation. * @throws InterruptedException is thrown if the current thread was externally interrupted. */ public AbstractServiceSimulator newInstance(final UnitController unitController, final ServiceType serviceType) throws InstantiationException, InterruptedException { return newInstance(new Pair<>(unitController, serviceType)); }
public Map<RoleType, String> getRoleConceptIdMap(){ Map<RoleType, String> roleConceptMap = new HashMap<>(); Map<String, Predicate> varSubMap = getVarSubMap(); Map<RoleType, Pair<String, Type>> roleVarMap = getRoleVarTypeMap(); roleVarMap.forEach( (role, varTypePair) -> { String var = varTypePair.getKey(); roleConceptMap.put(role, varSubMap.containsKey(var) ? varSubMap.get(var).getPredicateValue() : ""); }); return roleConceptMap; }
/** * Distribute the income to all the participants in a convoy. */ private void distributeCostsToAllConvoyParticipants(IConvoy convoy, Pair<Integer, Integer> amountBougth, int loaded, double discountBonus) { Map<IPlayer, Integer> capacityMap = convoy.getCapacityPerOwner(); long totalPrice = (long) Math.rint(-amountBougth.getValue() * loaded * discountBonus); updatePlayerByCapacityPercentage(convoy, capacityMap, totalPrice); } private void distributeIncomeToConvoyParticipants(IConvoy vessel, int avgPrice, int sold) {
@Override public Map<RoleType, Pair<String, Type>> getRoleVarTypeMap() { if (roleVarTypeMap == null) { if (varTypeRoleMap != null) { roleVarTypeMap = new HashMap<>(); varTypeRoleMap.forEach((var, tpair) -> { RoleType rt = tpair.getValue(); if (rt != null) roleVarTypeMap.put(rt, new Pair<>(var, tpair.getKey())); }); } else roleVarTypeMap = computeRoleVarTypeMap(); } return roleVarTypeMap; } }
public IntersectionPlaneBoxCalculator() { // Index ordering as in http://paulbourke.net/geometry/polygonise/ boxVertices[0] = new Point3D( 0.5, 0.5, -0.5); boxVertices[1] = new Point3D( 0.5, -0.5, -0.5); boxVertices[2] = new Point3D(-0.5, -0.5, -0.5); boxVertices[3] = new Point3D(-0.5, 0.5, -0.5); boxVertices[4] = new Point3D( 0.5, 0.5, 0.5); boxVertices[5] = new Point3D( 0.5, -0.5, 0.5); boxVertices[6] = new Point3D(-0.5, -0.5, 0.5); boxVertices[7] = new Point3D(-0.5, 0.5, 0.5); boxEdges.add(new Pair<>(boxVertices[0], boxVertices[1])); boxEdges.add(new Pair<>(boxVertices[1], boxVertices[2])); boxEdges.add(new Pair<>(boxVertices[2], boxVertices[3])); boxEdges.add(new Pair<>(boxVertices[3], boxVertices[0])); boxEdges.add(new Pair<>(boxVertices[4], boxVertices[5])); boxEdges.add(new Pair<>(boxVertices[5], boxVertices[6])); boxEdges.add(new Pair<>(boxVertices[6], boxVertices[7])); boxEdges.add(new Pair<>(boxVertices[7], boxVertices[4])); boxEdges.add(new Pair<>(boxVertices[0], boxVertices[4])); boxEdges.add(new Pair<>(boxVertices[1], boxVertices[5])); boxEdges.add(new Pair<>(boxVertices[2], boxVertices[6])); boxEdges.add(new Pair<>(boxVertices[3], boxVertices[7])); }
/** * Figure out what wares are needed in <code>nextStop</code>, that can be provided in the current town. * @param knowledge base knowledge * @param knowledgeCurrentTown knowledge of the current town * @param nextStop stop of the next city. * @return list of wares that can be delivered from the current city to the <code>nextStop</code> */ protected List<IWare> getWaresNeedIn(IProductionConsumptionKnowledge knowledge, ICityProductionConsumptionKnowledge knowledgeCurrentTown, ICity nextStop) { List<Pair<IWare, Number>> sortedNeeds; ICityProductionConsumptionKnowledge knowledgeFirstTown = knowledge.getKnowlege(nextStop); sortedNeeds = getMostNeededWares(knowledgeFirstTown); List<IWare> deliverWare = new ArrayList<>(); // wares to be bought in hometown and sold in nextStop for (Pair<IWare, Number> need : sortedNeeds) { if (knowledgeCurrentTown.getProductionAmount(need.getKey()) > 0) { deliverWare.add(need.getKey()); } } return deliverWare; }
/** * Figure out the ware that are most needed in the city. The need is calculated upon the knowledge * of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at * all, compared to wares that have more consumption than stored + produced. Also consider the amount of that ware * that is loaded on the <code>vessel</code>. That ware is treated the same way as if it stored in the city, with the * effect that on the first call the most needed ware might be BEER, but once an amount is bought the most needed ware might * change. * @param knowledge base knowledge * @param vessel on which the wares are loaded. * @return sorted list Pair of wares and their importants. The lower the number the more important. */ public List<Pair<IWare, Number>> getMostNeededWares(ICityProductionConsumptionKnowledge knowledge, INavigableVessel vessel) { List<Pair<IWare, Number>> sortedNeeds = getMostNeededWares(knowledge); for (ListIterator<Pair<IWare, Number>> iterator = sortedNeeds.listIterator(); iterator.hasNext(); ) { Pair<IWare, Number> need = iterator.next(); if (vessel.getWare(need.getKey()).getAmount() > 0) { int value = need.getValue().intValue() + vessel.getWare(need.getKey()).getAmount(); iterator.remove(); iterator.add(new Pair<>(need.getKey(), value)); } } return sortedNeeds.stream().sorted(new WareNeedComparator()).collect(Collectors.toList()); }
@Override public void run() { PlanarRegionsListMessage newMessage = planarRegionsListMessage.getAndSet(null); // Reset both clears by using only one pipe if (clearOcTree.getAndSet(false) | clear.getAndSet(false)) { meshAndMaterialToRender.set(new Pair<>(null, null)); return; } if (!enable.get()) return; uiMessager.submitStateRequestToModule(REAModuleAPI.RequestPlanarRegions); if (newMessage == null) return; meshAndMaterialToRender.set(generateMeshAndMaterial(newMessage)); }
@Override public void handleShipArrivesInPort(IShipEntersPortEvent event) { INavigableVessel vessel = event.getShip(); if (isMatchingTradeStrategy(vessel)) { IAIPlayer player = (IAIPlayer) vessel.getOwner(); ICity city = event.getCity(); SupplyCityMissionData missionData = (SupplyCityMissionData) player.getTradeMission(vessel); ICity targetCity = missionData.getTargetCity(); CentralStorageStrategyHint hint = (CentralStorageStrategyHint) player.getPlayerContext().getHints(targetCity).stream().filter(h -> h instanceof CentralStorageStrategyHint).findFirst().get(); CentralStorageHintContext context = (CentralStorageHintContext) hint.getContext(); if (city.equals(targetCity)) { // - unload oal to storage TransferToOfficeTradeStep transferToOfficeStep = createTransferToOfficeTradeStep(vessel, city); append(player, vessel, transferToOfficeStep); // - find best city to supply wares ICity nextStop = findProvidingWares(city, context.getWares(), context.getSuppliedCities(), player, vessel); // buy wares needed there ICityProductionConsumptionKnowledge cityKnowledge = player.getProductionAndConsumptionKnowledge().getKnowlege(nextStop); List<Pair<IWare, Number>> needs = getMostNeededWares(cityKnowledge, vessel); HashSet<IWare> buyWares = new HashSet<>(); needs.stream().forEach(pair -> buyWares.add(pair.getKey())); buyWares.removeAll(context.getWares()); addDefaultTradeSteps(vessel, player, city, nextStop, new HashSet<>(context.getWares()), buyWares, false); } else { addDefaultTradeSteps(vessel, player, city, targetCity, new HashSet<>(context.getWares()), new HashSet<>(context.getWares()), false); } executeTradeSteps(player, vessel); } }
/** * Instantiate a new service simulator compatible to the given config pair. * * @param configPair contains the simulation target and the type of service to simulate. * @return the simulator * @throws InstantiationException is thrown if any error occurs during the instantiation. * @throws InterruptedException is thrown if the current thread was externally interrupted. */ @Override public AbstractServiceSimulator newInstance(final Pair<UnitController, ServiceType> configPair) throws InstantiationException, InterruptedException { try { // try to return costum service simulator final String serviceSimulatorClassName = AbstractServiceSimulator.class.getPackage().getName() + "." + StringProcessor.transformUpperCaseToCamelCase(configPair.getValue().name()) + "Simulator"; return ((Class<? extends AbstractServiceSimulator>) Class.forName(serviceSimulatorClassName)).getConstructor(UnitController.class).newInstance(configPair.getKey()); } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | java.lang.InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) { ExceptionPrinter.printHistory("Could not find custom service simulator for " + configPair.getValue().getClass().getName() + "[" + configPair.getValue().name() + "]", ex, LOGGER, LogLevel.DEBUG); } // return generic service simulator return new GenericServiceSimulator(configPair.getKey(), configPair.getValue()); } }
.mapToObj(i -> { indexMap.get(e.getKey()).add(index.getAndIncrement()); return new Pair<>(e.getKey(), i); }) .collect(Collectors.toList()); final Pair<String, Integer> index1 = orderedIndices.get(i); final Pair<String, Integer> index2 = orderedIndices.get(j); final Skeleton3D skeleton1 = inputFrames.get(index1.getKey()).getSkeletons().get(index1.getValue()); final Skeleton3D skeleton2 = inputFrames.get(index2.getKey()).getSkeletons().get(index2.getValue()); if (index1.getKey().equals(index2.getKey()) || skeleton1.isEmpty() || skeleton2.isEmpty()) { distances[i][j] = Double.MAX_VALUE; } else {