Büroeinrichtung und optimale Platzwahl

October 25, 2010

This post is from the archive and therefore in German.

Auf der Arbeit wird das Büro neu eingerichtet, und es gibt mehrere Varianten wie die Leute sitzen könnten.

german

Ich habe deshalb ein einfaches Programm erstellt, welches unabhängig die Kombination mit der grössten gemeinsamen Zufriedenheit berechnet! Das Programm findet ihr ganz am Schluss des Posts.

Es wurden am Schluss über zwei Modelle abgestimmg, Modell B:

Modell B

Modell C:

bild

Es sollten alle Ihre Sitzwahlpräferenz für die beiden Modelle (B und C) bekannt geben, und zwar im folgenden Format:

Modell | Name | 1., 2., 3. Platz | Gewichtung für Platz 1., 2., 3.

Jeder konnte aus den 5 verfügbaren Sitzen 3 auswählen und diese mit Punkten gewichten.

Dabei ist bei der Gewichtung wichtig, genau 6 Punkte zu vergeben. Jeder Sitz muss zudem mindestens 1 Punkt haben. Wenn jemand z.B. unbedingt einen Platz möchte, kann er im Extremfall für einen Platz 4 Punkte und für die anderen beiden je 1 Punkte vergeben. Die Punkte müssen nicht ganzzahlig vergeben werden.

Ein fiktives Beispiel wäre z.B. John, der am liebsten auf Sitzplatz 3 sitzen würde. Zweite Präferenz wäre Sitzplatz 2, dritte Sitzplatz 4. Die erste Präferenz (also Sitzplatz 3) gewichtet John mit 3.2 Punkten, usw.

Modell B | John | 3 2 4 | 3.2 1.8 1

Es endete übrigens mit Variante C - maximale Punktzahl von 12.5 Punkten. Jeder hatte den Sitzplatz bekommen, welcher er als 1. Präferenz angegeben hat...

Das ganze Programm:

#include <iostream>
#include <string>
#include <cmath>
#include <vector>

using namespace std;

int findC(int actPoss, int actCand, int totCand) {
    int k;

    for (k=totCand; k>(totCand-actCand-1); k--) {
        actPoss %= (int)pow(3.0,k);
    }

    actPoss /= (int)pow(3.0,totCand-actCand-1);
    actPoss += actCand*(3);

    return actPoss;
}

int main() {
    int actCand, actPoss=0, totCand=0, c, bestP=0, l, notValid=0;
    string n;
    double c1, newScore=0, bestScore=0;
    vector<string> name;
    vector<int> choice;
    vector<double> rating;

    cout << "Welcome.\nReady to find the best possibility?\n";
    cout << "Then give me a number how many candidates you want to enter: ";
    cin >> totCand;
    cout << "\nFor each candidate, format your input as follow:\n";
    cout << "Name [P1] [P2] [P3] [R1] [R2] [R3]\n";
    cout << "P stands for a possibibility (slot) and R for Ranking Points\n\n";
    cout << "Example: John 4 3 2 3 2 1\n";

    for (actCand=0; actCand<totCand; actCand++) {
        cin >> n; name.push_back(n);
        cin >> c; choice.push_back(c);
        cin >> c; choice.push_back(c);
        cin >> c; choice.push_back(c);
        cin >> c1; rating.push_back(c1);
        cin >> c1; rating.push_back(c1);
        cin >> c1; rating.push_back(c1);
    }

    //Search for best Possibility
    for (actPoss=0;actPoss<pow(3.0,totCand);actPoss++) {
        newScore = 0;
        for (actCand=0;actCand<totCand;actCand++) {
           //Pick actual rating from Candidate
           newScore += rating[findC(actPoss, actCand, totCand)];
           for (l=(actCand-1); l>=0 ;l--) {
             if (choice[findC(actPoss, actCand, totCand)] 
                 == choice[findC(actPoss, l, totCand)]) {
                     notValid=1; 
                     break;
             }
           }
           if (notValid==1) {break;}
        }
        if (notValid==0){
                         if (newScore > bestScore) {
                                      bestScore = newScore; 
                                      bestP = actPoss;
                         }
        }
        notValid=0;
    }

    if (bestScore == 0) {cout << "No solution found, sorry.";}
    else {
         cout << "\n\nBest Possibility:\n" << bestP;
         cout << " with Score " << bestScore << "\n";
         for (actCand=0; actCand<totCand; actCand++) {
            cout << name[actCand] << " -> Place ";
            cout << choice[findC(bestP, actCand, totCand)] << "\n";
         }
    }
    cin >> totCand;
    return 0;
}