samedi 3 septembre 2016

My program doesn't enter if-else statements even if they are valid

this my function, it's supposed to return a list of operation, but it returns me only one operation, the one added in the first if statement. The program doesn't enter any of the next if-else statements and id doesn't return me any error.

Any help would be really appreciated.

    public ArrayList<Operation> opFunction(int startTrailerQuantity, Integer[][] timeMatrix,
        ArrayList<Double> quantities, int[] unrouted, Vehicule vehicule, Conducteur conducteur, TimeWindow tw,
        int start_shift, int setupTime) {

    ArrayList<Operation> operations = new ArrayList<Operation>();
    int cumulatedDrivingTime = 0;
    double trailerQuantity = 0;
    boolean passage_source = false;
    double sommeQuantite = 0, moyenneQuantite;

    for (int i = 0, j = quantities.size(); i < j; i++) {

        sommeQuantite = sommeQuantite + quantities.get(i);
    }

    moyenneQuantite = sommeQuantite / quantities.size();

    if (startTrailerQuantity == vehicule.getInitialQuantity() || startTrailerQuantity > moyenneQuantite) {

        cumulatedDrivingTime = timeMatrix[0][unrouted[0]] + setupTime;

        trailerQuantity = startTrailerQuantity - quantities.get(0);

        operations.add(new Operation(start_shift + timeMatrix[0][unrouted[0]], unrouted[0], quantities.get(0)));

    } else {

        cumulatedDrivingTime = timeMatrix[0][1] + setupTime;

        trailerQuantity = vehicule.getCapacity();

        operations.add(new Operation(0, 1, -(vehicule.getCapacity() - startTrailerQuantity)));

        passage_source = true;
    }

    System.out.println(cumulatedDrivingTime);

    for (int i = 0; i < unrouted.length; i++) {

        if (i + 1 > unrouted.length) {

            if (passage_source != false) {

                cumulatedDrivingTime = cumulatedDrivingTime + timeMatrix[1][unrouted[i]] + setupTime;
                trailerQuantity = trailerQuantity - quantities.get(i);

            } else {

                cumulatedDrivingTime = cumulatedDrivingTime + timeMatrix[unrouted[i]][unrouted[i + 1]] + setupTime;

                trailerQuantity = trailerQuantity - quantities.get(i + 1);

            }

            if (cumulatedDrivingTime <= conducteur.getMaxDrivingDuration()
                    && start_shift + cumulatedDrivingTime <= tw.getEnd()) {

                if (trailerQuantity >= quantities.get(i + 1)) {

                    operations.add(new Operation(0, unrouted[i + 1], quantities.get(i + 1)));

                    passage_source = false;

                } else {

                    cumulatedDrivingTime = cumulatedDrivingTime - timeMatrix[unrouted[i]][unrouted[i + 1]]
                            + timeMatrix[unrouted[i]][1] + setupTime;

                    if (cumulatedDrivingTime <= conducteur.getMaxDrivingDuration()
                            && start_shift + cumulatedDrivingTime <= tw.getEnd()) {

                        operations.add(new Operation(0, 1, -(vehicule.getCapacity() - trailerQuantity))); // la
                                                                                                            // quantité
                                                                                                            // du
                                                                                                            // chargement
                                                                                                            // est
                                                                                                            // négative

                        // après cette opération le véhicule est chargé et
                        // se trouve dans la source.
                        trailerQuantity = vehicule.getCapacity();

                        passage_source = true;
                    }
                }

            } else {

                // on soustrait le dernier temps ajouté depuis la ville à la
                // ville qui ne va pas être ajouté.

                cumulatedDrivingTime = cumulatedDrivingTime - timeMatrix[unrouted[i]][unrouted[i + 1]]
                        + timeMatrix[unrouted[i]][0];

                if (cumulatedDrivingTime <= conducteur.getMaxDrivingDuration()
                        && start_shift + cumulatedDrivingTime <= tw.getEnd()) {

                    operations.add(new Operation(0, 0, 0));

                }
            }

        }
    }
    System.out.println(operations.size());
    return operations;

}

Aucun commentaire:

Enregistrer un commentaire