Skip to content
TheChatArchiveThe Chat Archive
Perplexitypplx-70b-online· PerplexityHugging Face Arena Human Preference 55K

do you see anything wrong with my code: #include "itinerary.h" #include "graph.h"…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-1’s answer.
  1. User

    do you see anything wrong with my code: #include "itinerary.h" #include "graph.h" #include "graphUtils.h"

    #include

    using namespace std; using namespace boost;

    Itinerary::Itinerary() : tripLength(0) { }

    void Itinerary::addRoad(const Leg& roadSegment) { Vertex v1, v2;

    if (verticesByName.find(roadSegment.fromCity) == verticesByName.end()) {
        v1 = boost::add_vertex(g);
        verticesByName[roadSegment.fromCity] = v1;
    }
    else {
        v1 = verticesByName[roadSegment.fromCity];
    }
    
    if (verticesByName.find(roadSegment.toCity) == verticesByName.end()) {
        v2 = boost::add_vertex(g);
        verticesByName[roadSegment.toCity] = v2;
    }
    else {
        v2 = verticesByName[roadSegment.toCity];
    }
    
    boost::add_edge(v1, v2, g);
    boost::add_edge(v2, v1, g);
    

    }

    std::vector Itinerary::travelPlan(std::string startingCityName, std::string destinationCityName) { Vertex start = verticesByName[startingCityName]; Vertex end = verticesByName[destinationCityName];

    // Assume weightMap is a map of Edge to double that represents the distances between vertices
    std::map<Edge, double> weightMap;
    for (auto edge_it = boost::edges(g).first; edge_it != boost::edges(g).second; ++edge_it) {
        Edge edge = *edge_it;
        weightMap[edge] = g[edge].length;
    }
    
    std::vector<Vertex> path = findWeightedShortestPath(g, start, end, weightMap);
    
    std::vector<Leg> results;
    if (!path.empty()) {
        for (int i = 0; i < path.size() - 1; ++i) {
            Leg leg;
            leg.fromCity = g[path[i]].city;
            leg.toCity = g[path[i + 1]].city;
            leg.distance = weightMap[boost::edge(path[i], path[i + 1], g).first];
            results.push_back(leg);
        }
    }
    
    return results;
    

    }

    double Itinerary::getLastTripLength() const { return tripLength; }

  2. Perplexity Assistant

    There are a few issues in your code. Here are the main points:

    1. In the addRoad function, you are using verticesByName to store and retrieve vertices. However, you have not defined verticesByName in the Itinerary class. You should define it as a member variable of the Itinerary class.

    2. In the travelPlan function, you are using weightMap to store the weights of the edges. However, you have not defined weightMap in the Itinerary class. You should define it as a member variable of the Itinerary class or pass it as an argument to the function.

    Here's the corrected code:

    #include "itinerary.h"
    #include "graph.h"
    #include "graphUtils.h"
    
    #include <iostream>
    
    using namespace std;
    using namespace boost;
    
    Itinerary::Itinerary()
        : tripLength(0),
          verticesByName(make_assoc_property_map(StringToVertexMap))
    {
    }
    
    void Itinerary::addRoad(const Leg& roadSegment)
    {
        Vertex v1, v2;
    
        if (verticesByName.find(roadSegment.fromCity) == verticesByName.end()) {
            v1 = boost::add_vertex(g);
            verticesByName[roadSegment.fromCity] = v1;
        }
        else {
            v1 = verticesByName[roadSegment.fromCity];
        }
    
        if (verticesByName.find(roadSegment.toCity) == verticesByName.end()) {
            v2 = boost::add_vertex(g);
            verticesByName[roadSegment.toCity] = v2;
        }
        else {
            v2 = verticesByName[roadSegment.toCity];
        }
    
        boost::add_edge(v1, v2, g);
        boost::add_edge(v2, v1, g);
    }
    
    std::vector<Leg> Itinerary::travelPlan(std::string startingCityName,
        std
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

Identical first prompt