[关闭]
@w1024020103 2017-06-15T23:13:31.000000Z 字数 4493 阅读 1200

Project 3: Bear Maps, version 2.0

CS61B


采用17年的skeleton

Getting the Skeleton Files

when I try to run MapServer.java, I get these errors:

Error:(19, 23) java: 程序包com.google.gson不存在
Error:(21, 20) java: 程序包spark不存在
Error:(98, 9) java: 找不到符号
符号: 方法 staticFileLocation(java.lang.String)
位置: 类 MapServer

The following resources actually helped me out: I need to open Project Structure > Library > add > from Maven > search for "Gson 2.8.0" > Download > Add dependencies to pom.xml

resouces:

Google GSON Dependency not found
Gson User Guide
google/gson

image_1bh2a58a1gb8bsiuo1c05mrh9.png-14.4kB

每次run之前要先关掉console那里的tab,不然会报错java.net.BindException: Address already in use.

Assignment Overview

Three classes

image_1bh2gqein1mesf891qud1dqdm33m.png-18.1kB

the Rasterer class

image_1bh2gsf7fqpl1a20brc5liuc713.png-23.5kB

the GraphDB class

image_1bh2gt2i919hr5r67sg1tif1foe1g.png-19.7kB

the Router class

image_1bh2gtl741i6b1t1510shsbo1v1f1t.png-28.2kB

Biggest challenges

image_1bh2gum521j4n12bk11efv19cq2a.png-13.6kB

Map Rastering (Part I Overview)

params and Query Box

image_1bh2ph6pnjpk1gqt1f1d19c290f2n.png-66.5kB

returning 2D Array of strings

image_1bh2ptbiccbo50lr511vp12ju34.png-95.1kB

LonDPP Longitudinal distance per pixel

image_1bh2qb9fct22veb1td311oivtu3h.png-117.6kB

Key parameter names and concepts

image_1bh2qh8id1b7vu7mrac1nve1c623u.png-83.2kB

Map Rastering (API)

捣鼓了一下,pass了test.html.此处注意一下2D array的初始化:

  1. String [][] images = new String [][] {{"aaa","bbb","ccc"},{"ddd","eee","fff"},{"ggg","eee","hhh"}};

image_1bh41rb812fc1mu71n1rhhtnpr9.png-117.1kB

image_1bh42d5kn18qn8ihm1b1t2or3um.png-12.1kB

Suggested Approach for Rastering: QuadTree

image_1bh4gia0j74g1llo1oaopag19iv13.png-67.6kB

image_1bh6mful51ibia1qn2o1i701s0k9.png-361.1kB

image_1bh725ro0ae016t9qk88a31egom.png-150.8kB

image_1bh7dk9h992v1alil7b1rff1t3r9.png-131.5kB

I found these words most useful in this part:

The problem of finding the correct images for a given query is thus equivalent to going to the shallowest level whose LonDPP is less than or equal to the query box, and finding all images at that level that intersect the query box.

报错:java.lang.StackOverflowError
at Rasterer QuadTree.(Rasterer.java:40)
at Rasterer QuadTree.(Rasterer.java:40)
at Rasterer QuadTree.(Rasterer.java:40)

helpful resources for constructing QuadTree:

Quadtrees: Implementation

However, when I try to NEW a QuadTree as the initialQuadTree, I ran into one problem:

'QuadTree' is not an enclosing class

  1. initialQuadTree = new QuadTree(new QuadTree.Node());

然后干脆新建了一个QuadTree类,但还是报同样的错。

this helped me out:
Is not an enclosing class Java

现在,运行出来的结果只显示了这些code对应的:

  1. System.out.println(params);
  2. System.out.println(biggestLonDPP);

其余的都没有显示,说明运行出问题了:

  1. System.out.println(bestLonDPP);
  2. System.out.println(returnTiles.size());

卡了好几天没进展,实在觉得做不下来,问了YYN要proj3的代码。跟学Algorithm Part 1第一遍时候一样,我希望自己至少能读懂别人的代码,理解的基础上能模仿着写出来。但这也让我担心开学后做作业会很困难。没有办法,转专业的道路前段肯定会有难捱的时期,刷完CS61B必须开始刷算法课,刷题,有机会最好再刷一些Project,为开学做好准备。

很大的知识漏洞,java IO这一块儿。

写到RasteredImages.java里的getDepth()方法时有一疑惑,为什么要写

  1. public int getDepth() {
  2. //images[i][j] = "img/" + images[i][j] + ".png"
  3. return images[0][0].length() - 8;
  4. }

这里的images难道不是process之前的images吗,按理说应该是

123

这样的格式,还没有

img/ + 123 + .png

呀?为什么depth要-8呢?

上一个问题还没有解决,按照参考答案写的,然后测试却始终不通过,报以下错:

image_1bi0qhs4giki18p6q21gu2tq99.png-96.3kB

看样子是我的ArrayList nodes 是空的,但一直没法debug,找不到问题出在哪儿。

我一部分一部分地测试,发现出错的方法有:
getNodes():java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
helpGetNodes():java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
getImages():java.lang.ArrayIndexOutOfBoundsException: 3
insert:java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

如果不按照它的Insert里面的num而是按照我自己的,会出现出来的图不完整的问题:

image_1bi2ttvnt1nbk1iu1bag184d5i9.png-175.9kB
image_1bi2tuea4193ld401f1vas31e0jm.png-889.4kB

检查来检查去,发现我出问题的地方是二位数组的row和col分不清:

  1. //return all images corresponding to the qualified nodes
  2. public String[][] getImages(ArrayList<Node> nodes){
  3. double firstULlat = nodes.get(0).upLeftLatitude;
  4. int col = 0;
  5. for(Node node: nodes){
  6. if(node.upLeftLatitude == firstULlat){
  7. col += 1;
  8. }
  9. }
  10. int row = nodes.size() / col;
  11. //[[img/13.png, img/14.png, img/23.png, img/24.png],
  12. //[img/31.png, img/32.png, img/41.png, img/42.png],
  13. //[img/33.png, img/34.png, img/43.png, img/44.png]]
  14. //2D array, [][] first bracket stands for the number of 1D array which equals to the number of rows,
  15. //second stands for the number of element of the 1D array which equals to the number of cols.
  16. String[][] images = new String[row][col];
  17. int count = 0;
  18. for(int i = 0; i < row; i++){
  19. for(int j = 0; j < col; j++){
  20. images[i][j] = nodes.get(count).getImgFile();
  21. count += 1;
  22. }
  23. }
  24. return images;
  25. }

在这个方法里,我先开始写成了

  1. int count = 0;
  2. for(int i = 0; i < col; i++){
  3. for(int j = 0; j < row; j++){
  4. images[i][j] = nodes.get(count).getImgFile();
  5. count += 1;
  6. }
  7. }

导致一直出错。

注意到,返回的String[][]是这样的格式:

  1. [[img/13.png, img/14.png, img/23.png, img/24.png],
  2. [img/31.png, img/32.png, img/41.png, img/42.png],
  3. [img/33.png, img/34.png, img/43.png, img/44.png]]

它是由3个1D array构成,每个1D array有四个元素,所以row是3,col是4.
写入二维数组的时候,应该是先row后col.

Routing & Location Data (Part II)

The first step of this part of the project is to build a graph representation of the contents of berkeley.osm.

Your job will be to override the startElement and endElement methods so that when the SAX parser has completed, you have built a graph.

Part of your job will be decide how to store the graph itself in your GraphDB class. Note that the final step of graph construction is to "clean" the graph, i.e. to destroy all nodes that are disconnected. Unlike the Princeton graph implementation, your GraphDB will need to permit the insertion and deletion of nodes.

int:
int 数据类型是32位、有符号的以二进制补码表示的整数;
最小值是 -2,147,483,648(-2^31);
最大值是 2,147,483,647(2^31 - 1);
一般地整型变量默认为 int 类型;
默认值是 0 ;
例子:int a = 100000, int b = -200000。
long:
long 数据类型是 64 位、有符号的以二进制补码表示的整数;
最小值是 -9,223,372,036,854,775,808(-2^63);
最大值是 9,223,372,036,854,775,807(2^63 -1);
这种类型主要使用在需要比较大整数的系统上;
默认值是 0L;
例子: long a = 100000L,Long b = -200000L。
"L"理论上不分大小写,但是若写成"l"容易与数字"1"混淆,不容易分辩。所以最好大写。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注