Java Code Examples for gnu.trove.list.array.TIntArrayList#add()
The following examples show how to use
gnu.trove.list.array.TIntArrayList#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSparseBinaryMatrixTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testOr() { AbstractSparseBinaryMatrix matrix2 = getTestMatrix(); boolean isTest = true; matrix2.set(new int[] { 1 }, new int[] { 1 }, isTest); AbstractSparseBinaryMatrix matrix = getTestMatrix(); assertEquals(0, matrix.getTrueCount(1)); assertEquals(0, matrix.getSparseIndices().length); matrix.or(matrix2); assertEquals(1, matrix.getTrueCount(1)); assertEquals(7, matrix.getSparseIndices().length); // Now for trove collection matrix = getTestMatrix(); assertEquals(0, matrix.getTrueCount(1)); assertEquals(0, matrix.getSparseIndices().length); TIntArrayList tl = new TIntArrayList(); tl.add(1); matrix.or(tl); assertEquals(1, matrix.getTrueCount(1)); assertEquals(7, matrix.getSparseIndices().length); }
Example 2
Source File: DefaultReconfigurationProblem.java From scheduler with GNU Lesser General Public License v3.0 | 6 votes |
private void addContinuousResourceCapacities() { TIntArrayList cUse = new TIntArrayList(); List<IntVar> iUse = new ArrayList<>(); for (int j = 0; j < getVMs().size(); j++) { VMTransition a = vmActions.get(j); if (a.getDSlice() != null) { iUse.add(csp.intVar(1)); } if (a.getCSlice() != null) { cUse.add(1); } } ChocoView v = getView(Cumulatives.VIEW_ID); if (v == null) { throw SchedulerModelingException.missingView(model, Cumulatives.VIEW_ID); } ((Cumulatives) v).addDim(getNbRunningVMs(), cUse.toArray(), iUse.toArray(new IntVar[iUse.size()])); }
Example 3
Source File: QuestEngine.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void registerQuestSkill(int skillId, int questId) { if (!questOnUseSkill.containsKey(skillId)) { TIntArrayList questSkills = new TIntArrayList(); questSkills.add(questId); questOnUseSkill.put(skillId, questSkills); } else { questOnUseSkill.get(skillId).add(questId); } }
Example 4
Source File: CShareableResource.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean inject(Parameters ps, ReconfigurationProblem p) throws SchedulerException { this.rp = p; this.references = new HashMap<>(); this.clones = new HashMap<>(); csp = p.getModel(); this.source = p.getSourceModel(); List<Node> nodes = p.getNodes(); phyRcUsage = new ArrayList<>(nodes.size()); virtRcUsage = new ArrayList<>(nodes.size()); this.ratios = new TDoubleArrayList(nodes.size()); id = ShareableResource.VIEW_ID_BASE + rc.getResourceIdentifier(); for (Node nId : p.getNodes()) { phyRcUsage.add(csp.intVar(p.makeVarLabel("phyRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, rc.getCapacity(nId), true)); virtRcUsage.add(csp.intVar(p.makeVarLabel("virtRcUsage('", rc.getResourceIdentifier(), "', '", nId, "')"), 0, Integer.MAX_VALUE / 100, true)); ratios.add(UNCHECKED_RATIO); } phyRcUsage = Collections.unmodifiableList(phyRcUsage); virtRcUsage = Collections.unmodifiableList(virtRcUsage); //Bin packing for the node vmAllocation vmAllocation = new TIntArrayList(); for (VM vmId : p.getVMs()) { VMTransition a = p.getVMAction(vmId); Slice slice = a.getDSlice(); if (slice == null) { //The VMs will not be running, so its consumption is set to 0 vmAllocation.add(0); } else { //We don't know about the next VM usage for the moment, -1 is used by default to allow to detect an //non-updated value. vmAllocation.add(-1); } } return true; }
Example 5
Source File: NodeTerminal.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
NodeTerminal(Ref<? extends VariantManagerHolder> network, int node) { super(network); this.node = node; int variantArraySize = network.get().getVariantManager().getVariantArraySize(); v = new TDoubleArrayList(variantArraySize); angle = new TDoubleArrayList(variantArraySize); connectedComponentNumber = new TIntArrayList(variantArraySize); synchronousComponentNumber = new TIntArrayList(variantArraySize); for (int i = 0; i < variantArraySize; i++) { v.add(Double.NaN); angle.add(Double.NaN); connectedComponentNumber.add(0); synchronousComponentNumber.add(0); } }
Example 6
Source File: MyArraysTest.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testentropy() { int[] w; float[] ww; float e; w= new int[]{ 1, 2, 3, 4, 0, 0, 0 }; e = MyArrays.entropy(w); System.out.print(e + " "); ww= new float[]{ 1, 0, 0, 0, 0, 0, 0 }; e = MyArrays.entropy(ww); System.out.print(e + " "); System.out.println(); TIntArrayList www = new TIntArrayList(); for(int i=0;i<100;i++){ www.add(1); w = www.toArray(); e = MyArrays.entropy(w); System.out.print(e + " "); System.out.println(e/w.length); } System.out.println(); ww= new float[]{ 0.5f, 0.5f }; e = MyArrays.entropy(ww); System.out.print(e + " "); }
Example 7
Source File: ArrayUtils.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Scans the specified values and applies the {@link Condition} to each * value, returning the indexes of the values where the condition evaluates * to true. * * @param values the values to test * @param c the condition used to test each value * @return */ public static <T> int[] where(double[] values, Condition<T> c) { TIntArrayList retVal = new TIntArrayList(); int len = values.length; for (int i = 0; i < len; i++) { if (c.eval(values[i])) { retVal.add(i); } } return retVal.toArray(); }
Example 8
Source File: UndirectedGraphImpl.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Override public int[] getEdges() { TIntArrayList t = new TIntArrayList(getEdgeCount()); for (int e = 0; e < edges.size(); e++) { if (edges.get(e) != null) { t.add(e); } } return t.toArray(); }
Example 9
Source File: ArrayUtils.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns an array of values that test true for all of the * specified {@link Condition}s. * * @param values * @param conditions * @return */ public static int[] retainLogicalAnd(int[] values, Condition<?>[] conditions) { TIntArrayList l = new TIntArrayList(); for (int i = 0; i < values.length; i++) { boolean result = true; for (int j = 0; j < conditions.length && result; j++) { result &= conditions[j].eval(values[i]); } if (result) l.add(values[i]); } return l.toArray(); }
Example 10
Source File: QuestEngine.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void registerOnBonusApply(int questId, BonusType bonusType) { if (!questOnBonusApply.containsKey(bonusType)) { TIntArrayList onBonusApplyQuests = new TIntArrayList(); onBonusApplyQuests.add(questId); questOnBonusApply.put(bonusType, onBonusApplyQuests); } else { questOnBonusApply.get(bonusType).add(questId); } }
Example 11
Source File: QuestEngine.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void registerCanAct(int questId, int templateId) { if (!questCanAct.containsKey(templateId)) { TIntArrayList questSkills = new TIntArrayList(); questSkills.add(questId); questCanAct.put(templateId, questSkills); } else { questCanAct.get(templateId).add(questId); } }
Example 12
Source File: LocalOnlineApplication.java From ipst with Mozilla Public License 2.0 | 5 votes |
public LocalOnlineApplication(OnlineConfig config, ComputationManager computationManager, ScheduledExecutorService ses, ExecutorService executorService, boolean enableJmx) throws IllegalAccessException, InstantiationException, InstanceAlreadyExistsException, MBeanRegistrationException, MalformedObjectNameException, NotCompliantMBeanException, IOException { this.config = config; this.computationManager = Objects.requireNonNull(computationManager); this.ses = Objects.requireNonNull(ses); this.executorService = Objects.requireNonNull(executorService); LOGGER.info("Version: {}", Version.VERSION); this.enableJmx = enableJmx; busyCores = new TIntArrayList(); ComputationResourcesStatus status = computationManager.getResourcesStatus(); int v = status.getBusyCores(); for (int i = 0; i < BUSY_CORES_HISTORY_SIZE; i++) { busyCores.add(v); } if (enableJmx) { // create and register online application mbean ManagementFactory.getPlatformMBeanServer().registerMBean(this, new ObjectName(BEAN_NAME)); } future = ses.scheduleAtFixedRate(() -> { try { notifyBusyCoresUpdate(false); } catch (Throwable t) { LOGGER.error(t.toString(), t); } }, 0, 20, TimeUnit.SECONDS); }
Example 13
Source File: CResourceCapacity.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
private boolean injectContinuous(ReconfigurationProblem rp, CShareableResource rcm) throws SchedulerException { //The constraint must be already satisfied if (!cstr.isSatisfied(rp.getSourceModel())) { rp.getLogger().error("The constraint '{}' must be already satisfied to provide a continuous restriction", cstr); return false; } int[] alias = new int[cstr.getInvolvedNodes().size()]; int i = 0; for (Node n : cstr.getInvolvedNodes()) { alias[i++] = rp.getNode(n); } TIntArrayList cUse = new TIntArrayList(); List<IntVar> dUse = new ArrayList<>(); for (VM vmId : rp.getVMs()) { VMTransition a = rp.getVMAction(vmId); Slice c = a.getCSlice(); Slice d = a.getDSlice(); if (c != null) { cUse.add(rcm.getSourceResource().getConsumption(vmId)); } if (d != null) { int m = rcm.getVMAllocation(rp.getVM(vmId)); dUse.add(rp.fixed(m, "vmAllocation('", rcm.getResourceIdentifier(), "', '", vmId, "'")); } } ChocoView v = rp.getRequiredView(AliasedCumulatives.VIEW_ID); ((AliasedCumulatives) v).addDim(cstr.getAmount(), cUse.toArray(), dUse.toArray(new IntVar[dUse.size()]), alias); return true; }
Example 14
Source File: QuestEngine.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public void registerOnKillRanked(AbyssRankEnum playerRank, int questId) { for (int rank = playerRank.getId(); rank < 19; rank++) { if (!questOnKillRanked.containsKey(AbyssRankEnum.getRankById(rank))) { TIntArrayList onKillRankedQuests = new TIntArrayList(); onKillRankedQuests.add(questId); questOnKillRanked.put(AbyssRankEnum.getRankById(rank), onKillRankedQuests); } else { questOnKillRanked.get(AbyssRankEnum.getRankById(rank)).add(questId); } } }
Example 15
Source File: JointParser.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
public static int[] addFeature(IFeatureAlphabet fa, ArrayList<String> str, int ysize) { TIntArrayList indices = new TIntArrayList(); String constant = "////"; str.add(constant); for(String s: str){ int i = fa.lookupIndex(s,ysize); if(i!=-1) indices.add(i); } return indices.toArray(); }
Example 16
Source File: ArrayUtils.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Scans the specified values and applies the {@link Condition} to each * value, returning the indexes of the values where the condition evaluates * to true. * * @param values the values to test * @param c the condition used to test each value * @return */ public static <T> int[] where(T[] values, Condition<T> c) { TIntArrayList retVal = new TIntArrayList(); for (int i = 0; i < values.length; i++) { if (c.eval(values[i])) { retVal.add(i); } } return retVal.toArray(); }
Example 17
Source File: Topology.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Get the points in the neighborhood of a point. * * A point's neighborhood is the n-dimensional hypercube with sides ranging * [center - radius, center + radius], inclusive. For example, if there are two * dimensions and the radius is 3, the neighborhood is 6x6. Neighborhoods are * truncated when they are near an edge. * * @param centerIndex The index of the point. The coordinates are expressed as a single index by * using the dimensions as a mixed radix definition. For example, in dimensions * 42x10, the point [1, 4] is index 1*420 + 4*10 = 460. * @param radius The radius of this neighborhood about the centerIndex. * @return The points in the neighborhood, including centerIndex. */ public int[] neighborhood(int centerIndex, int radius) { centerPosition = coordinatesFromIndex(centerIndex); igs = IntStream.range(0, dimensions.length) .mapToObj(i -> IntGenerator.of(Math.max(0, centerPosition[i] - radius), Math.min(dimensions[i] - 1, centerPosition[i] + radius) + 1)) .toArray(IntGenerator[]::new); List<TIntList> result = new ArrayList<>(); result.add(new TIntArrayList()); List<TIntList> interim = new ArrayList<>(); for(IntGenerator pool : igs) { int size = result.size(); interim.clear(); interim.addAll(result); result.clear(); for(int x = 0;x < size;x++) { TIntList lx = interim.get(x); pool.reset(); for(int y = 0;y < pool.size();y++) { int py = pool.next(); TIntArrayList tl = new TIntArrayList(); tl.addAll(lx); tl.add(py); result.add(tl); } } } return result.stream().mapToInt(tl -> indexFromCoordinates(tl.toArray())).toArray(); }
Example 18
Source File: Util.java From PE-HFT-Java with GNU General Public License v3.0 | 5 votes |
public static TIntArrayList getMillisecFromHourStart(TLongArrayList t){ TIntArrayList hour= new TIntArrayList(t.size()); for(int i=0; i<t.size();i++) hour.add( (int) (t.getQuick(i)%3600000L) ); return hour; }
Example 19
Source File: ByteBufUtils.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static TIntList readIntList(PacketBuffer buf) { TIntArrayList intArrayList = new TIntArrayList(); int amount = buf.readVarInt(); for (int i = 0; i < amount; i++) { intArrayList.add(buf.readVarInt()); } return intArrayList; }
Example 20
Source File: CShareableResource.java From scheduler with GNU Lesser General Public License v3.0 | 4 votes |
private boolean linkVirtualToPhysicalUsage() throws SchedulerException { int min = Integer.MAX_VALUE; //Number of VMs with a 0 usage int nbZeroes = 0; for (int vId = 0; vId < vmAllocation.size(); vId++) { int alloc = vmAllocation.get(vId); if (alloc > 0) { min = Math.min(alloc, min); } else { nbZeroes++; } } for (int nIdx = 0; nIdx < ratios.size(); nIdx++) { if (!linkVirtualToPhysicalUsage(nIdx)) { return false; } if (!capHosting(nIdx, min, nbZeroes)) { return false; } } //The slice scheduling constraint that is necessary TIntArrayList cUse = new TIntArrayList(); List<IntVar> dUse = new ArrayList<>(); for (VMTransition a : rp.getVMActions()) { VM vm = a.getVM(); Slice c = a.getCSlice(); Slice d = a.getDSlice(); if (c != null) { cUse.add(getSourceResource().getConsumption(vm)); } if (d != null) { int m = getVMAllocation(rp.getVM(vm)); dUse.add(rp.fixed(m, "vmAllocation('", getResourceIdentifier(), "', '", vm, "'")); } } Cumulatives v = (Cumulatives) rp.getRequiredView(Cumulatives.VIEW_ID); v.addDim(virtRcUsage, cUse.toArray(), dUse.toArray(new IntVar[dUse.size()])); checkInitialSatisfaction(); return true; }