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

Overview
Comment:remove unneccessary double storage of trader instances
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c95dc85730320a1471615614fe59831e3a2aae84
User & Date: ravenspoint 2016-05-28 20:54:28
Context
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
20:27
add trade check-in: 01a7d7f020 user: ravenspoint tags: trunk
Changes

Changes to longestpath.cbp.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
		<Compiler>
			<Add option="-march=i686" />
			<Add option="-std=c++11" />
			<Add option="-Wall" />
			<Add option="-fexceptions" />
			<Add directory="$(#boost)" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Unit filename="trade.h" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>







|









31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
		<Compiler>
			<Add option="-march=i686" />
			<Add option="-std=c++11" />
			<Add option="-Wall" />
			<Add option="-fexceptions" />
			<Add directory="$(#boost)" />
		</Compiler>
		<Unit filename="trade.cpp" />
		<Unit filename="trade.h" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>

Changes to trade.h.

161
162
163
164
165
166
167
168

169

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
    }
};

class cVillage
{
public:
    cTraveler myTraveler;
    vector< cTrader > myTrader;

    trade_graph_t myGraph;

    void 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;


        // initial starting point
        myTrader.push_back( cTrader(  eCommodity::wood,  eCommodity::wood, 1));

        myTrader.push_back( cTrader( eCommodity::wood, eCommodity::sand, 2));
        myTrader.push_back( cTrader( eCommodity::sand, eCommodity::gras, 0.5));
        myTrader.push_back( cTrader( eCommodity::gras, eCommodity::sand, 1));
        myTrader.push_back( cTrader( eCommodity::sand, eCommodity::wood, 0.25));
        myTrader.push_back( cTrader( eCommodity::gras, eCommodity::wood, 0.5));

        for( auto& t : myTrader )
        {
            myGraph[ add_vertex( myGraph ) ] = t;
        }

    }
    void Display()
    {
        int index = 0;
        for( auto& t : myTrader )
        {
            if( index != 0 )
            {

                cout << "Trader " << index << " ";
                t.Display();
            }
            index++;
        }
    }
    void ConstructSensibleTrips()
    {
        // A sensible trip betwee two traders:
        // the source is selling what the target is buying

        // loop over all pairs of traders
        for( int s = 0; s < (int)myTrader.size(); s++)
        {
            for( int t = 1; t < (int)myTrader.size(); t++)
            {
                if( myTrader[ s ].mySell == myTrader[ t].myBuy )
                {
                    //cout << s << " -> " << t << endl;
                    add_edge( s, t, myGraph );
                }
            }
        }
    }
    void Travel()
    {
        ConstructSensibleTrips();
        //ConvertToDAG();
        myTraveler.myfTrading = true;
        float bestQuantity = -1;
        vector< int > bestpath;
        unsigned int src, dst;







<
>

>
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







161
162
163
164
165
166
167

168
169
170
171
172


























173
174












175
176
















177
178
179
180
181
182
183
184
    }
};

class cVillage
{
public:
    cTraveler myTraveler;


    trade_graph_t myGraph;

    void ConstructProblem1();



























    void Display();













    void ConstructSensibleTrips();

















     void Travel()
    {
        ConstructSensibleTrips();
        //ConvertToDAG();
        myTraveler.myfTrading = true;
        float bestQuantity = -1;
        vector< int > bestpath;
        unsigned int src, dst;