public static void main(String[] args) throws IOException{
		
		long startMili = System.currentTimeMillis();
		
		//read raw ranking data and queries
		ReadData();
		ReadQuery();
		
		//ranking for movie-indexed data
		Moviecomparator comp1 = new Moviecomparator();
		Collections.sort(MovieRating, comp1);
		
		//ranking for user-indexed data
		Usercomparator comp2 = new Usercomparator();
		Collections.sort(UserRating, comp2);
		
		//rebuild movie-indexed data copy
		int CurMovie = 0;
		ArrayList<DataTuple> tmplist = new ArrayList<DataTuple>();
		for(DataTuple tmptuple : MovieRating){
			if(tmptuple.getMovie() != CurMovie){
				MovieFirstRating.add(tmplist);
				tmplist = new ArrayList<DataTuple>();
				CurMovie = tmptuple.getMovie();
			}
			DataTuple tmp = new DataTuple();
			tmp.setMovie(tmptuple.getMovie());
			tmp.setUser(tmptuple.getUser());
			tmp.setRating(tmptuple.getRating());
			tmplist.add(tmp);
		}
		MovieFirstRating.add(tmplist);
		MovieFirstRating.remove(0);
		MovieFirstRating.trimToSize();
		
		//rebuild user-indexed data copy
		int CurUser = 0;
		tmplist = new ArrayList<DataTuple>();
		for(DataTuple tmptuple : UserRating){
			if(tmptuple.getUser() != CurUser){
				UserFirstRating.add(tmplist);
				tmplist = new ArrayList<DataTuple>();
				CurUser = tmptuple.getUser();
			}
			DataTuple tmp = new DataTuple();
			tmp.setMovie(tmptuple.getMovie());
			tmp.setUser(tmptuple.getUser());
			tmp.setRating(tmptuple.getRating());
			tmplist.add(tmp);
		}
		UserFirstRating.add(tmplist);
		UserFirstRating.remove(0);
		UserFirstRating.trimToSize();
		
		//user-user rating algorithm
		System.out.println("user-user rating start!");
		Rating.rating_user(QuerySet, UserFirstRating);
		WriteResult(QuerySet, UserUserOutput);
		System.out.println("user-user rating finish!");
		
		//movie-movie rating algorithm
		System.out.println("movie-movie rating start!");
		Rating.rating_movie(QuerySet, MovieFirstRating);
		WriteResult(QuerySet, MovieMovieOutput);
		System.out.println("movie-movie rating finish!");
		
		//user-user normalized rating algorithm
		System.out.println("user-user normalized rating start!");
		Rating.rating_user_norm(QuerySet, UserFirstRating);
		WriteResult(QuerySet, UserUserNormOutput);
		System.out.println("user-user normalized rating finish!");
		
		//custom rating algorithm
		System.out.println("custom rating start!");
		Rating.rating_custom(QuerySet, UserFirstRating);
		WriteResult(QuerySet, CustomOutput);
		System.out.println("custom rating finish!");
		
		//get running time
		long endMili = System.currentTimeMillis();
		System.out.println("Total running time is " + (endMili - startMili) + "ms");		
		System.out.println("Finished!");

	}