@Override public DoubleVector getColumnVector(int col) { int[] rows = matrix.keys(); DoubleVector v = new SparseDoubleVector(getRowCount()); for (int row : rows) { v.set(row, get(row, col)); } return v; }
@Override public DoubleVector multiplyVectorRow(DoubleVector v) { DoubleVector result = new SparseDoubleVector(this.getRowCount()); for (int row : matrix.keys()) { Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero(); double sum = 0.0d; while (iterateNonZero.hasNext()) { DoubleVectorElement e = iterateNonZero.next(); sum += (e.getValue() * v.get(e.getIndex())); } result.set(row, sum); } return result; }
@Override public int[] rowIndices() { return matrix.keys(); }
/** * Method getCursedWeaponsIds. * * @return int[] */ public int[] getCursedWeaponsIds() { return _cursedWeaponsMap.keys(); }
@Override public List<RouteInfoLocation> searchTransportRouteStops( double latitude, double longitude, LatLon locationToGo, int zoom) { long now = System.currentTimeMillis(); final LatLon loc = new LatLon(latitude, longitude); double tileNumberX = MapUtils.getTileNumberX(zoom, longitude); double tileNumberY = MapUtils.getTileNumberY(zoom, latitude); double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY - 0.5); double bottomLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY + 0.5); double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX - 0.5); double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 0.5); SearchRequest<TransportStop> req = BinaryMapIndexReader.buildSearchTransportRequest( MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberX(rightLongitude), MapUtils.get31TileNumberY(topLatitude), MapUtils.get31TileNumberY(bottomLatitude), -1, null); List<RouteInfoLocation> listRoutes = new ArrayList<RouteInfoLocation>(); try { List<TransportStop> stops = file.searchTransportIndex(req); TIntObjectHashMap<TransportStop> stopsToProcess = new TIntObjectHashMap<TransportStop>(); for (TransportStop s : stops) { for (int ref : s.getReferencesToRoutes()) { TransportStop exist = stopsToProcess.get(ref); if (exist == null || MapUtils.getDistance(loc, s.getLocation()) < MapUtils.getDistance(loc, exist.getLocation())) { stopsToProcess.put(ref, s); } } } TIntObjectHashMap<TransportRoute> transportRoutes = file.getTransportRoutes(stopsToProcess.keys()); for (int ref : stopsToProcess.keys()) { TransportRoute route = transportRoutes.get(ref); TransportStop s = stopsToProcess.get(ref); for (int i = 0; i < 2; i++) { boolean direction = i == 0; List<TransportStop> stps = direction ? route.getForwardStops() : route.getBackwardStops(); // load only part while (!stps.isEmpty() && (stps.get(0).getId().longValue() != s.getId().longValue())) { stps.remove(0); } if (!stps.isEmpty()) { RouteInfoLocation r = new RouteInfoLocation(); r.setRoute(route); r.setStart(stps.get(0)); r.setDirection(direction); if (locationToGo != null) { int distToLoc = Integer.MAX_VALUE; for (TransportStop st : stps) { double ndist = MapUtils.getDistance(locationToGo, st.getLocation()); if (ndist < distToLoc) { distToLoc = (int) ndist; r.setStop(st); r.setDistToLocation(distToLoc); } } } listRoutes.add(r); } } } if (log.isDebugEnabled()) { log.debug( String.format( "Search for routes done in %s ms found %s.", //$NON-NLS-1$ System.currentTimeMillis() - now, listRoutes.size())); } if (locationToGo != null) { Collections.sort( listRoutes, new Comparator<RouteInfoLocation>() { @Override public int compare(RouteInfoLocation object1, RouteInfoLocation object2) { int x = (int) (MapUtils.getDistance(loc, object1.getStart().getLocation()) + object1.getDistToLocation()); int y = (int) (MapUtils.getDistance(loc, object2.getStart().getLocation()) + object2.getDistToLocation()); return x - y; } }); } else { Collections.sort( listRoutes, new Comparator<RouteInfoLocation>() { @Override public int compare(RouteInfoLocation object1, RouteInfoLocation object2) { return Double.compare( MapUtils.getDistance(loc, object1.getStart().getLocation()), MapUtils.getDistance(loc, object2.getStart().getLocation())); } }); } } catch (IOException e) { log.error("Disk error", e); // $NON-NLS-1$ } return listRoutes; }
public void generateNewBitmap( RenderingContext rc, List<BinaryMapDataObject> objects, Bitmap bmp, RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) { long now = System.currentTimeMillis(); // fill area Canvas cv = new Canvas(bmp); if (rc.defaultColor != 0) { cv.drawColor(rc.defaultColor); } if (objects != null && !objects.isEmpty() && rc.width > 0 && rc.height > 0) { // init rendering context rc.tileDivisor = (int) (1 << (31 - rc.zoom)); rc.cosRotateTileSize = FloatMath.cos((float) Math.toRadians(rc.rotate)) * TILE_SIZE; rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE; // put in order map TIntObjectHashMap<TIntArrayList> orderMap = sortObjectsByProperOrder(rc, objects, render); int objCount = 0; int[] keys = orderMap.keys(); Arrays.sort(keys); boolean shadowDrawn = false; for (int k = 0; k < keys.length; k++) { if (!shadowDrawn && (keys[k] >> 2) >= rc.shadowLevelMin && (keys[k] >> 2) <= rc.shadowLevelMax && rc.shadowRenderingMode > 1) { for (int ki = k; ki < keys.length; ki++) { if ((keys[ki] >> 2) > rc.shadowLevelMax || rc.interrupted) { break; } TIntArrayList list = orderMap.get(keys[ki]); for (int j = 0; j < list.size(); j++) { int i = list.get(j); int ind = i >> 8; int l = i & 0xff; BinaryMapDataObject obj = objects.get(ind); // show text only for main type drawObj(obj, render, cv, rc, l, l == 0, true, (keys[ki] & 3)); objCount++; } } shadowDrawn = true; } if (rc.interrupted) { return; } TIntArrayList list = orderMap.get(keys[k]); for (int j = 0; j < list.size(); j++) { int i = list.get(j); int ind = i >> 8; int l = i & 0xff; BinaryMapDataObject obj = objects.get(ind); // show text only for main type drawObj(obj, render, cv, rc, l, l == 0, false, (keys[k] & 3)); objCount++; } rc.lastRenderedKey = (keys[k] >> 2); if (objCount > 25) { notifyListeners(notifyList); objCount = 0; } } long beforeIconTextTime = System.currentTimeMillis() - now; notifyListeners(notifyList); drawIconsOverCanvas(rc, cv); notifyListeners(notifyList); textRenderer.drawTextOverCanvas(rc, cv, rc.useEnglishNames); long time = System.currentTimeMillis() - now; rc.renderingDebugInfo = String.format( "Rendering: %s ms (%s text)\n" + "(%s points, %s points inside, %s of %s objects visible)", //$NON-NLS-1$ time, time - beforeIconTextTime, rc.pointCount, rc.pointInsideCount, rc.visible, rc.allObjects); log.info(rc.renderingDebugInfo); } }
public void importBukmak( List<Bookmark2> xbukmak, boolean tumpuk, TObjectIntHashMap<Bookmark2> bukmakToRelIdMap, TIntLongHashMap labelRelIdToAbsIdMap, TIntObjectHashMap<TIntList> bukmak2RelIdToLabelRelIdsMap) { SQLiteDatabase db = helper.getWritableDatabase(); db.beginTransaction(); try { TIntLongHashMap bukmakRelIdToAbsIdMap = new TIntLongHashMap(); { // tulis bukmak2 baru String[] params1 = new String[1]; String[] params2 = new String[2]; for (Bookmark2 bukmak : xbukmak) { int bukmak2_relId = bukmakToRelIdMap.get(bukmak); params2[0] = String.valueOf(bukmak.ari); params2[1] = String.valueOf(bukmak.jenis); long _id = -1; boolean ada = false; Cursor cursor = db.query( Db.TABEL_Bukmak2, null, Db.Bukmak2.ari + "=? and " + Db.Bukmak2.jenis + "=?", params2, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ if (cursor.moveToNext()) { ada = true; _id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); /* [1] */ } cursor.close(); // --------------------------------- dapet _id dari // ada tumpuk: delete insert [2] // ada !tumpuk: (nop) [1] // !ada tumpuk: insert [2] // !ada !tumpuk: insert [2] if (ada && tumpuk) { params1[0] = String.valueOf(_id); db.delete(Db.TABEL_Bukmak2, "_id=?", params1); // $NON-NLS-1$ db.delete( Db.TABEL_Bukmak2_Label, Db.Bukmak2_Label.bukmak2_id + "=?", params1); // $NON-NLS-1$ } if ((ada && tumpuk) || (!ada)) { _id = db.insert(Db.TABEL_Bukmak2, null, bukmak.toContentValues()); /* [2] */ } // map it bukmakRelIdToAbsIdMap.put(bukmak2_relId, _id); } } { // sekarang pemasangan label String where = Db.Bukmak2_Label.bukmak2_id + "=?"; // $NON-NLS-1$ String[] params = {null}; ContentValues cv = new ContentValues(); // nlabel>0 tumpuk: delete insert // nlabel>0 !tumpuk: (nop) // nlabel=0 tumpuk: insert // nlabel=0 !tumpuk: insert for (int bukmak2_relId : bukmak2RelIdToLabelRelIdsMap.keys()) { TIntList label_relIds = bukmak2RelIdToLabelRelIdsMap.get(bukmak2_relId); long bukmak2_id = bukmakRelIdToAbsIdMap.get(bukmak2_relId); if (bukmak2_id > 0) { params[0] = String.valueOf(bukmak2_id); // cek ada berapa label untuk bukmak2_id ini int nlabel = 0; Cursor c = db.rawQuery( "select count(*) from " + Db.TABEL_Bukmak2_Label + " where " + where, params); //$NON-NLS-1$ //$NON-NLS-2$ try { c.moveToNext(); nlabel = c.getInt(0); } finally { c.close(); } if (nlabel > 0 && tumpuk) { db.delete(Db.TABEL_Bukmak2_Label, where, params); } if ((nlabel > 0 && tumpuk) || (!(nlabel > 0))) { for (int label_relId : label_relIds.toArray()) { long label_id = labelRelIdToAbsIdMap.get(label_relId); if (label_id > 0) { cv.put(Db.Bukmak2_Label.bukmak2_id, bukmak2_id); cv.put(Db.Bukmak2_Label.label_id, label_id); db.insert(Db.TABEL_Bukmak2_Label, null, cv); } else { Log.w(TAG, "label_id ngaco!: " + label_id); // $NON-NLS-1$ } } } } else { Log.w(TAG, "bukmak2_id ngaco!: " + bukmak2_id); // $NON-NLS-1$ } } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }