0

arraylists の arraylist があり、外側の arraylist 内の各 arraylist には、次の値の holidayId、country、countryValue、duration、durationValue、accType、accTypeValue、holSubType、holSubTypeValue、weather、weatherValue、pricePP、pricePPValue、recommendationScore が保持されます。これらはすべてオブジェクトとして保持されます。recommendationScore を使用して配列リストを double 型に変換して並べ替える方法があるかどうかを知りたいですか? または、この問題にアプローチできる他の方法はありますか?

前もって感謝します

public class RecAlgorithmImpl {

public static ArrayList<Double> attRanking(ArrayList<Double> attRank){

    ArrayList<Double> attWeight = new ArrayList<>();
    double weight;

    /*Loops through the rankings given in the questionnaire 
     * and sets a new number for better recommendation accuracy */
    for(int i = 0; i < attRank.size();i++){

        if(attRank.get(i) == 1){
            attRank.set(i, 7.0);
        }
        else if(attRank.get(i) == 2){
            attRank.set(i, 6.0);
        }
        else if(attRank.get(i) == 3){
            attRank.set(i, 5.0);
        }
        else if(attRank.get(i) == 4){
            attRank.set(i, 4.0);
        }
        else if(attRank.get(i) == 5){
            attRank.set(i, 3.0);
        }
        else if(attRank.get(i) == 6){
            attRank.set(i, 2.0);
        }           
        else if(attRank.get(i) == 0){
            attRank.set(i, 1.0);
        }
    }

            //Loop through the ranked values and assign a weighting to each attribute
    for(int j = 0; j < attRank.size(); j++){
        weight = (attRank.get(j))/28;
        attWeight.add(weight);
    }

    for(int k = 0; k < attWeight.size();k++){
        System.out.println(attWeight.get(k));
    }
    return attWeight;
}

public static ArrayList<ArrayList> valuePoints(ArrayList<ArrayList> valuePoints){
        //DataRetrievalImpl database = new DataRetrievalImpl();
        ArrayList<ArrayList> holiday = new ArrayList<>();

        //test info
        ArrayList<String> test = new ArrayList<>();
        test.add("stuff1");
        test.add("stuff2");
        test.add("stuff3");
        test.add("stuff4");
        test.add("stuff5");
        test.add("stuff6");
        holiday.add(test);
        ArrayList<String> test1 = new ArrayList<>();
        test1.add("stuff11");
        test1.add("stuff12");
        test1.add("stuff13");
        test1.add("stuff14");
        test1.add("stuff15");
        test1.add("stuff16");
        holiday.add(test1);


        ArrayList<ArrayList> holidayScore = new ArrayList<>(); // creates new arraylist to hold the 6 attributes and their value points to be used in recommendation score
        //database information
        /*boolean condition = false;
        String[] select = null;
        String[] from = null;
        String[] where = null;
        holiday = database.getData(condition, select, from, where);*/

        //Loops through the holiday arraylist which contains all the holidays and adds the attributes that we need to the new one along with default points
        for(int i = 0; i < holiday.size(); i++){
            holidayScore.add(new ArrayList());
            holidayScore.get(i).add(holiday.get(i).get(0));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(1));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(2));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(3));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(4));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(5));
            holidayScore.get(i).add("0");
        }

        //Loops through the holidayScore arraylist checking the attributes against the valuePoints array list and 
        //modifying the value points where the two attribute values are equivalent in both arraylists
        //each if statement checks that each attrbute value is equivalent, successful matches record the points from valuePoints into holidayScore
        for(int j = 0; j < holidayScore.size(); j++){

            if(holidayScore.get(j).get(0) == valuePoints.get(j).get(0)){
                holidayScore.get(j).set(1, valuePoints.get(j).get(1));
            }

            if(holidayScore.get(j).get(2) == valuePoints.get(j).get(2)){
                holidayScore.get(j).set(3, valuePoints.get(j).get(3));
            }

            if(holidayScore.get(j).get(4) == valuePoints.get(j).get(4)){
                holidayScore.get(j).set(5, valuePoints.get(j).get(5));
            }

            if(holidayScore.get(j).get(6) == valuePoints.get(j).get(6)){
                holidayScore.get(j).set(7, valuePoints.get(j).get(7));
            }

            if(holidayScore.get(j).get(8) == valuePoints.get(j).get(8)){
                holidayScore.get(j).set(9, valuePoints.get(j).get(9));
            }

            if(holidayScore.get(j).get(10) == valuePoints.get(j).get(10)){
                holidayScore.get(j).set(11, valuePoints.get(j).get(11));
            }  
        }

        System.out.println(holiday);
        System.out.println("----------------------------------------------------");
        System.out.println(holidayScore);
        return holidayScore;
}

public static void recommendation(ArrayList<Double> weightedAttr, ArrayList<ArrayList> holidayScores){

        //each variable holds the current value points for that attribute value
        double countryValue;
        double durationValue;
        double accTypeValue;
        double holSubTypeValue;
        double weatherValue;
        double pricePPValue;
        double recScore;

        //Loops through the holidayScores arraylist convert the value points into double which is multiplied by the appropriate attribute weighting
        //this gives a decimal score for each attribute which is summed up for the final recommendation score and added to the end of the arraylist
        for(int k = 0; k < holidayScores.size(); k++){
            countryValue = Double.parseDouble(holidayScores.get(k).get(1).toString());
            durationValue = Double.parseDouble(holidayScores.get(k).get(3).toString());
            accTypeValue = Double.parseDouble(holidayScores.get(k).get(5).toString());
            holSubTypeValue = Double.parseDouble(holidayScores.get(k).get(7).toString());
            weatherValue = Double.parseDouble(holidayScores.get(k).get(9).toString());
            pricePPValue = Double.parseDouble(holidayScores.get(k).get(11).toString());
            recScore = (countryValue * weightedAttr.get(0));
            recScore = recScore + (durationValue * weightedAttr.get(1));
            recScore = recScore + (accTypeValue * weightedAttr.get(2));
            recScore = recScore + (holSubTypeValue * weightedAttr.get(3));
            recScore = recScore + (weatherValue * weightedAttr.get(4));
            recScore = recScore + (pricePPValue * weightedAttr.get(5));
            holidayScores.get(k).add(recScore);
        }

        System.out.println(holidayScores);
}

}

4

1 に答える 1

1

arraylist (内部) のすべての値を保持するオブジェクトを実装する必要があります。Comparable次に、そのチェックを簡単に実装できますrecommendationScore

于 2013-02-21T03:13:21.903 に答える