Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add trade,cpp main
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:62cd02833a7980dec95d74abb7eaf1aa677d34be
User & Date: ravenspoint 2016-05-28 21:21:26
Context
2016-05-29
00:12
cVillage::AddTrader method check-in: bba070fa45 user: ravenspoint tags: trunk
2016-05-28
21:21
add trade,cpp main check-in: 62cd02833a user: ravenspoint tags: trunk
20:54
remove unneccessary double storage of trader instances check-in: c95dc85730 user: ravenspoint tags: trunk
Changes

Added trade.cpp.









































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

#include <iostream>
#include <random>

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/bellman_ford_shortest_paths.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/depth_first_search.hpp>

using namespace std;
using namespace boost;

#include "trade.h"

void cVillage::ConstructProblem1()
{
    static eCommodity hold = eCommodity::wood;
    static float quantity = 1;
    myTraveler.myHold = &hold;
    myTraveler.myQuantity = &quantity;
    myTraveler.myInitiallHold = hold;
    myTraveler.myInitialQuantity = quantity;

    static vector<int> path;
    myTraveler.myPath = &path;

    myGraph[ add_vertex( myGraph ) ] =  cTrader(  eCommodity::wood,  eCommodity::wood, 1);

    myGraph[ add_vertex( myGraph ) ] = cTrader( eCommodity::wood, eCommodity::sand, 2);
    myGraph[ add_vertex( myGraph ) ] = cTrader( eCommodity::sand, eCommodity::gras, 0.5);
    myGraph[ add_vertex( myGraph ) ] = cTrader( eCommodity::gras, eCommodity::sand, 1);
    myGraph[ add_vertex( myGraph ) ] = cTrader( eCommodity::sand, eCommodity::wood, 0.25);
    myGraph[ add_vertex( myGraph ) ] = cTrader( eCommodity::gras, eCommodity::wood, 0.5);

}

void cVillage::Display()
{
    int index = 0;
    graph_traits<trade_graph_t>::vertex_iterator vi, vi_end;
    for (boost::tie(vi, vi_end) = vertices(myGraph); vi != vi_end; ++vi)
    {
        if( index != 0 )
        {
            cout << "Trader " << index << " ";
            myGraph[ *vi ].Display();
        }
        index++;
    }
}
void cVillage::ConstructSensibleTrips()
{
    // A sensible trip betwee two traders:
    // the source is selling what the target is buying

    // loop over all pairs of traders

    graph_traits<trade_graph_t>::vertex_iterator svi, svi_end, tvi, tvi_end;
    for (boost::tie(svi, svi_end) = vertices(myGraph); svi != svi_end; ++svi)
    {
        int index = 0;
        for (boost::tie(tvi, tvi_end) = vertices(myGraph); tvi != tvi_end; ++tvi)
        {
            if( index != 0 )
            {
                if( myGraph[ *svi ].mySell == myGraph[ *tvi ].myBuy )
                    add_edge( *svi, *tvi, myGraph );
            }
            index++;
        }
    }
}
int main()
{
    cVillage village;
    village.ConstructProblem1();
    village.Display();
    village.Travel();

    return 0;
}