-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEvcSolver.cpp
More file actions
executable file
·1521 lines (1235 loc) · 60.2 KB
/
Copy pathEvcSolver.cpp
File metadata and controls
executable file
·1521 lines (1235 loc) · 60.2 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2011 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions at http://help.arcgis.com/en/sdk/10.0/usageRestrictions.htm
// ===============================================================================================
// Evacuation Solver: Main class Implementation
// Description:
//
// Copyright (C) 2014 Kaveh Shahabi
// Distributed under the Apache Software License, Version 2.0. (See accompanying file LICENSE.txt)
//
// Author: Kaveh Shahabi
// URL: http://github.com/spatial-computing/CASPER
// ===============================================================================================
#include "stdafx.h"
#include "NameConstants.h"
#include "EvcSolver.h"
//******************************************************************************************/
// INASolver
STDMETHODIMP EvcSolver::Bind(INAContext* pContext, IDENetworkDataset* pNetwork, IGPMessages* pMessages)
{
// Bind() is a method used to re-associate the solver with a given network dataset and its schema. Calling Bind()
// on the solver re-attaches the solver to the NAContext based on the current network dataset settings.
// This is typically used to update the solver and its context based on changes in the network dataset's available
// restrictions, hierarchy attributes, cost attributes, etc.
// load network attributes for later configuration and usage
// this will be used to load restriction and also to load proper impedance (cost) value
INetworkAttribute2Ptr networkAttrib = nullptr;
long count, i;
HRESULT hr = S_OK;
esriNetworkAttributeUsageType utype;
esriNetworkAttributeDataType dtype;
IUnknownPtr unk;
if (pNetwork)
{
if (FAILED(hr = pNetwork->get_Attributes(&allAttribs))) return hr;
if (FAILED(hr = allAttribs->get_Count(&count))) return hr;
turnAttribs.clear();
costAttribs.clear();
discriptiveAttribs.clear();
for (i = 0; i < count; i++)
{
if (FAILED(hr = allAttribs->get_Element(i, &unk))) return hr;
networkAttrib = unk;
if (FAILED(hr = networkAttrib->get_UsageType(&utype))) return hr;
if (FAILED(hr = networkAttrib->get_DataType(&dtype))) return hr;
if (utype == esriNAUTRestriction) turnAttribs.insert(turnAttribs.end(), networkAttrib);
else if (utype == esriNAUTCost) costAttribs.insert(costAttribs.end(), networkAttrib);
else if (utype == esriNAUTDescriptor && (dtype == esriNADTDouble || dtype == esriNADTInteger))
discriptiveAttribs.insert(discriptiveAttribs.end(), networkAttrib);
}
if (costAttribs.size() < 1 && pMessages) pMessages->AddError(-1, L"There are no cost attributes in the network dataset.");
if (discriptiveAttribs.size() < 1 && pMessages) pMessages->AddError(-1, L"There are no descriptive attributes in the network dataset to be used as street capacity.");
if (costAttributeID == -1 && costAttribs.size() > 0) costAttribs[0]->get_ID(&costAttributeID);
if (capAttributeID == -1 && discriptiveAttribs.size() > 0) discriptiveAttribs[0]->get_ID(&capAttributeID);
// Agents setup
// NOTE: this is an appropriate place to find and attach any agents used by this solver.
// For example, the route solver would attach the directions agent.
INamedSetPtr agents;
IUnknownPtr pStreet;
INAContextHelperPtr ipContextHelper(pContext);
if (FAILED(hr = pContext->get_Agents(&agents))) return hr;
if (FAILED(hr = agents->get_ItemByName(L"StreetDirectionsAgent", &pStreet))) return hr;
if (!pStreet)
{
pStreetAgent = INAStreetDirectionsAgentPtr(CLSID_NAStreetDirectionsAgent);
((INAAgentPtr)pStreetAgent)->Initialize(pNetwork, ipContextHelper);
if (FAILED(hr = agents->Add(L"StreetDirectionsAgent", pStreetAgent))) return hr;
}
else pStreetAgent = pStreet;
}
return hr;
}
STDMETHODIMP EvcSolver::CreateLayer(INAContext * pContext, INALayer ** ppLayer)
{
if (!ppLayer) return E_POINTER;
*ppLayer = nullptr;
// This is an appropriate place to check if the user is licensed to run
// your solver and fail with "E_NOT_LICENSED" or similar.
// Create our custom symbolizer and use it to create the NALayer.
// NOTE: we are assuming here that there is only one symbolizer to
// consider. The Network Analyst framework and ESRI solvers support the notion
// that there can be many symbolizers in CATID_NetworkAnalystSymbolizer.
// One can iterate the objects in this category and call the Applies()
// method to see if the symbolizer should be used for a particular solver/context.
// There is also a get_Priority() method that is used to determine which
// to use if many Apply.
INASymbolizerPtr ipNASymbolizer(CLSID_EvcSolverSymbolizer);
return ipNASymbolizer->CreateLayer(pContext, ppLayer);
}
STDMETHODIMP EvcSolver::UpdateLayer(INALayer* pLayer, VARIANT_BOOL* pLayerUpdated)
{
if (!pLayer || !pLayerUpdated) return E_POINTER;
// This method is called after Solve() and gives us a chance to react to the results of
// the Solve and change the layer. For example, the Service Area solver updates
// its layer renderers after Solve has been called to adjust for unique values.
// We will not need to update our layer, since our renderers will remain the same throughout
*pLayerUpdated = VARIANT_FALSE;
return S_OK;
}
STDMETHODIMP EvcSolver::CreateContext(IDENetworkDataset* pNetwork, BSTR contextName, INAContext** ppNAContext)
{
if (!pNetwork || !ppNAContext) return E_POINTER;
if (!contextName || !::wcslen(contextName)) return E_INVALIDARG;
HRESULT hr;
*ppNAContext = nullptr;
// CreateContext() is called by the command that creates the solver and
// initializes it. Below we'll:
//
// - create the class definitions
// - set up defaults
//
// After this method is called, this class should be prepared to have
// its solve method called.
// This is an appropriate place to check if the user is licensed to run
// your solver and fail with "E_NOT_LICENSED" or similar.
// Get the NDS SpatialRef, that will be the same for the context as well as all spatial NAClasses
IDEGeoDatasetPtr ipDEGeoDataset(pNetwork);
if (!ipDEGeoDataset) return E_INVALIDARG;
ISpatialReferencePtr ipNAContextSR;
if (FAILED(hr = ipDEGeoDataset->get_SpatialReference(&ipNAContextSR))) return hr;
IUnknownPtr ipUnknown;
INamedSetPtr ipNAClassDefinitions;
INAClassDefinitionPtr ipEvacueePointsClassDef, ipRoutesClassDef, ipZonesClassDef, ipEdgeStatClassDef, ipFlocksClassDef, ipDynamicChangeClassDef;
// Build the class definitions
if (FAILED(hr = BuildClassDefinitions(ipNAContextSR, &ipNAClassDefinitions, pNetwork))) return hr;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_EVACUEES_NAME), &ipUnknown);
ipEvacueePointsClassDef = ipUnknown;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_ZONES_NAME), &ipUnknown);
ipZonesClassDef = ipUnknown;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_DYNCHANGES_NAME), &ipUnknown);
ipDynamicChangeClassDef = ipUnknown;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_ROUTES_NAME), &ipUnknown);
ipRoutesClassDef = ipUnknown;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_EDGES_NAME), &ipUnknown);
ipEdgeStatClassDef = ipUnknown;
ipNAClassDefinitions->get_ItemByName(ATL::CComBSTR(CS_FLOCKS_NAME), &ipUnknown);
ipFlocksClassDef = ipUnknown;
// Create a context and initialize it
INAContextPtr ipNAContext(CLSID_NAContext);
INAContextEditPtr ipNAContextEdit(ipNAContext);
if (FAILED(hr = ipNAContextEdit->Initialize(contextName, pNetwork))) return hr;
if (FAILED(hr = ipNAContextEdit->putref_Solver(static_cast<INASolver*>(this)))) return hr;
// Create NAClasses for each of our class definitions
INamedSetPtr ipNAClasses;
INAClassPtr ipNAClass;
if (FAILED(hr = ipNAContext->get_NAClasses(&ipNAClasses))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipZonesClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_ZONES_NAME), (IUnknownPtr)ipNAClass))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipEvacueePointsClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_EVACUEES_NAME), (IUnknownPtr)ipNAClass))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipDynamicChangeClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_DYNCHANGES_NAME), (IUnknownPtr)ipNAClass))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipRoutesClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_ROUTES_NAME), (IUnknownPtr)ipNAClass))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipEdgeStatClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_EDGES_NAME), (IUnknownPtr)ipNAClass))) return hr;
if (FAILED(hr = ipNAContextEdit->CreateAnalysisClass(ipFlocksClassDef, &ipNAClass))) return hr;
if (FAILED(hr = ipNAClasses->Add(ATL::CComBSTR(CS_FLOCKS_NAME), (IUnknownPtr)ipNAClass))) return hr;
// NOTE: this is an appropriate place to set up any hierarchy defaults if your
// solver supports using a hierarchy attribute (this solver does not). This is
// also an appropriate place to set the default impedance attribute if you
// had one.
// Initialize the default field mappings
// NOTE: this is an appropriate place to set up any default field mappings to be used
// Return the context once it has been fully created and initialized
*ppNAContext = ipNAContext;
ipNAContext->AddRef();
// Set up our solver defaults
m_outputLineType = esriNAOutputLineTrueShapeWithMeasure;
costAttributeID = -1;
capAttributeID = -1;
SaturationPerCap = 500.0;
CriticalDensPerCap = 10.0;
solverMethod = EvcSolverMethod::CASPERSolver;
trafficModel = EvcTrafficModel::POWERModel;
flockingProfile = FLOCK_PROFILE_CAR;
m_CreateTraversalResult = VARIANT_TRUE;
m_FindBestSequence = VARIANT_FALSE;
m_PreserveFirstStop = VARIANT_FALSE;
m_PreserveLastStop = VARIANT_FALSE;
m_UseTimeWindows = VARIANT_FALSE;
evacueeGroupingOption = EvacueeGrouping::None;
CASPERDynamicMode = DynamicMode::Simple;
VarExportEdgeStat = VARIANT_TRUE;
costPerDensity = 0.0f;
flockingEnabled = VARIANT_FALSE;
twoWayShareCapacity = VARIANT_TRUE;
ThreeGenCARMA = VARIANT_TRUE;
flockingSnapInterval = 0.1f;
flockingSimulationInterval = 0.01;
initDelayCostPerPop = 0.01;
CARMAPerformanceRatio = 0.1f;
selfishRatio = 0.0f;
iterateRatio = 0.6f;
backtrack = esriNFSBAllowBacktrack;
CarmaSortCriteria = CARMASort::BWCont;
savedVersion = c_version;
return S_OK;
}
#pragma warning(push)
#pragma warning(disable : 4100) /* Ignore warnings for unreferenced function parameters */
STDMETHODIMP EvcSolver::UpdateContext(INAContext* pNAContext, IDENetworkDataset* pNetwork, IGPMessages* pMessages)
{
// UpdateContext() is a method used to update the context based on any changes that may have been made to the
// solver settings. This typically includes changes to the set of accumulation attribute names, etc., which can
// be set as fields in the context's NAClass schemas
return S_OK;
}
#pragma warning(pop)
//******************************************************************************************/
// IPersistStream
STDMETHODIMP EvcSolver::IsDirty()
{
return (m_bPersistDirty ? S_OK : S_FALSE);
}
STDMETHODIMP EvcSolver::Load(IStream* pStm)
{
if (!pStm) return E_POINTER;
ULONG numBytes;
HRESULT hr;
// We need to check the saved version number
if (FAILED(hr = pStm->Read(&savedVersion, sizeof(savedVersion), &numBytes))) return hr;
// We only support versions less than or equal to the current c_version
if (savedVersion > c_version || savedVersion <= 0) return E_FAIL;
// We need to read our persisted solver settings
// version 1
if (FAILED(hr = pStm->Read(&m_outputLineType, sizeof(m_outputLineType), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&costAttributeID, sizeof(costAttributeID), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&capAttributeID, sizeof(capAttributeID), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&trafficModel, sizeof(trafficModel), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&solverMethod, sizeof(solverMethod), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&SaturationPerCap, sizeof(SaturationPerCap), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&CriticalDensPerCap, sizeof(CriticalDensPerCap), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&m_CreateTraversalResult, sizeof(m_CreateTraversalResult), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&m_FindBestSequence, sizeof(m_FindBestSequence), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&m_PreserveFirstStop, sizeof(m_PreserveFirstStop), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&m_PreserveLastStop, sizeof(m_PreserveLastStop), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&m_UseTimeWindows, sizeof(m_UseTimeWindows), &numBytes))) return hr;
if (savedVersion < 7)
{
VARIANT_BOOL separable;
evacueeGroupingOption = EvacueeGrouping::None;
if (FAILED(hr = pStm->Read(&separable, sizeof(separable), &numBytes))) return hr;
if (separable == VARIANT_TRUE) evacueeGroupingOption |= EvacueeGrouping::Separate;
}
else if (FAILED(hr = pStm->Read(&evacueeGroupingOption, sizeof(evacueeGroupingOption), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&VarExportEdgeStat, sizeof(VarExportEdgeStat), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&backtrack, sizeof(backtrack), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&costPerDensity, sizeof(costPerDensity), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&flockingEnabled, sizeof(flockingEnabled), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&flockingSnapInterval, sizeof(flockingSnapInterval), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&flockingSimulationInterval, sizeof(flockingSimulationInterval), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&twoWayShareCapacity, sizeof(twoWayShareCapacity), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&initDelayCostPerPop, sizeof(initDelayCostPerPop), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&flockingProfile, sizeof(flockingProfile), &numBytes))) return hr;
if (FAILED(hr = pStm->Read(&CARMAPerformanceRatio, sizeof(CARMAPerformanceRatio), &numBytes))) return hr;
//version 2
if (savedVersion >= 2)
{
if (FAILED(hr = pStm->Read(&ThreeGenCARMA, sizeof(ThreeGenCARMA), &numBytes))) return hr;
}
else
{
ThreeGenCARMA = VARIANT_TRUE;
savedVersion = 2;
}
//version 4
if (savedVersion >= 4)
{
if (FAILED(hr = pStm->Read(&selfishRatio, sizeof(selfishRatio), &numBytes))) return hr;
}
else
{
selfishRatio = 0.0f;
savedVersion = 4;
}
//version 5
if (savedVersion >= 5)
{
if (FAILED(hr = pStm->Read(&CarmaSortCriteria, sizeof(CarmaSortCriteria), &numBytes))) return hr;
}
else
{
CarmaSortCriteria = CARMASort::BWCont;
savedVersion = 5;
}
//version 6
if (savedVersion >= 6)
{
if (FAILED(hr = pStm->Read(&iterateRatio, sizeof(iterateRatio), &numBytes))) return hr;
}
else
{
iterateRatio = 0.0f;
savedVersion = 6;
}
//version 6
if (savedVersion >= 8)
{
if (FAILED(hr = pStm->Read(&CASPERDynamicMode, sizeof(CASPERDynamicMode), &numBytes))) return hr;
}
else
{
CASPERDynamicMode = DynamicMode::Disabled;
savedVersion = 8;
}
CARMAPerformanceRatio = min(max(CARMAPerformanceRatio, 0.0f), 1.0f);
selfishRatio = min(max(selfishRatio, 0.0f), 1.0f);
iterateRatio = min(max(iterateRatio, 0.0f), 1.0f);
m_bPersistDirty = false;
return S_OK;
}
STDMETHODIMP EvcSolver::Save(IStream* pStm, BOOL fClearDirty)
{
if (fClearDirty) m_bPersistDirty = false;
ULONG numBytes;
HRESULT hr;
// We need to persist the c_version number
if (FAILED(hr = pStm->Write(&c_version, sizeof(c_version), &numBytes))) return hr;
// We need to persist our solver settings
if (FAILED(hr = pStm->Write(&m_outputLineType, sizeof(m_outputLineType), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&costAttributeID, sizeof(costAttributeID), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&capAttributeID, sizeof(capAttributeID), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&trafficModel, sizeof(trafficModel), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&solverMethod, sizeof(solverMethod), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&SaturationPerCap, sizeof(SaturationPerCap), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&CriticalDensPerCap, sizeof(CriticalDensPerCap), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&m_CreateTraversalResult, sizeof(m_CreateTraversalResult), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&m_FindBestSequence, sizeof(m_FindBestSequence), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&m_PreserveFirstStop, sizeof(m_PreserveFirstStop), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&m_PreserveLastStop, sizeof(m_PreserveLastStop), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&m_UseTimeWindows, sizeof(m_UseTimeWindows), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&evacueeGroupingOption, sizeof(evacueeGroupingOption), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&VarExportEdgeStat, sizeof(VarExportEdgeStat), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&backtrack, sizeof(backtrack), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&costPerDensity, sizeof(costPerDensity), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&flockingEnabled, sizeof(flockingEnabled), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&flockingSnapInterval, sizeof(flockingSnapInterval), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&flockingSimulationInterval, sizeof(flockingSimulationInterval), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&twoWayShareCapacity, sizeof(twoWayShareCapacity), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&initDelayCostPerPop, sizeof(initDelayCostPerPop), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&flockingProfile, sizeof(flockingProfile), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&CARMAPerformanceRatio, sizeof(CARMAPerformanceRatio), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&ThreeGenCARMA, sizeof(ThreeGenCARMA), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&selfishRatio, sizeof(selfishRatio), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&CarmaSortCriteria, sizeof(CarmaSortCriteria), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&iterateRatio, sizeof(iterateRatio), &numBytes))) return hr;
if (FAILED(hr = pStm->Write(&CASPERDynamicMode, sizeof(CASPERDynamicMode), &numBytes))) return hr;
return S_OK;
}
STDMETHODIMP EvcSolver::GetSizeMax(_ULARGE_INTEGER* pCbSize)
{
if (!pCbSize) return E_POINTER;
pCbSize->HighPart = 0;
pCbSize->LowPart = sizeof(short);
return S_OK;
}
STDMETHODIMP EvcSolver::GetClassID(CLSID *pClassID)
{
if (!pClassID) return E_POINTER;
*pClassID = __uuidof(EvcSolver);
return S_OK;
}
//******************************************************************************************/
// private methods
HRESULT EvcSolver::BuildClassDefinitions(ISpatialReference* pSpatialRef, INamedSet** ppDefinitions, IDENetworkDataset* pDENDS)
{
if (!pSpatialRef || !ppDefinitions) return E_POINTER;
// This function creates the class definitions for the EvcSolver.
// Recall, class definitions are in-memory feature classes that store the
// inputs and outputs for a solver. This solver's class definitions are:
// Zones (input) Safe zones determine the end locations
// - OID of the search
// - Shape
// - Name
// - (NALocation fields)
// Evacuee Points (input) Evacuee points determine the start locations
// - OID of the search
// - Shape
// - Name
// - Population number of un-seperatable people/cars at this location
// - (NALocation fields)
// Routes (output) Evacuation routes
// - OID
// - Shape evacuation route (polyline)
// - EvcOID Evacuee user ID
// - EvcTime Evacuation cost on this route
// - OrgTime Evacuation cost assuming unlimited capacity
// - RoutedPop The population who would use this route
// Edges (output) Edge/street lines with their population reservations
// - OID
// - Shape edge/street shape (polyline)
// - EdgeID Edge ID from NetworkDataset. there could be at most two edges (different directions) with one edgeID.
// - Direction Direction of travel on this edge
// - SourceID Refers to source street file ID
// - SourceOID Refers to oid of the shape in the street file
// - ReservPop The total population who would use this edge at some time
// - TravCost Traversal cost based on the selected evacuation method on this edge
// - OrgCost Original traversal cost of the edge without any population
HRESULT hr = S_OK;
// Create the class definitions named set and the variables needed to properly instantiate them
INamedSetPtr ipClassDefinitions(CLSID_NamedSet);
INAClassDefinitionPtr ipClassDef;
INAClassDefinitionEditPtr ipClassDefEdit;
IUIDPtr ipIUID;
IFieldsPtr ipFields;
IFieldsEditPtr ipFieldsEdit;
IFieldPtr ipField;
IFieldEditPtr ipFieldEdit;
//******************************************************************************************/
// Zones class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriNetworkAnalyst.NALocationFeature")))) return hr;
ipClassDefEdit->putref_ClassCLSID(ipIUID);
// Create the fields for the class definition
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
// Create and add an OID field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add a Shape field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
{
IGeometryDefEditPtr ipGeoDef(CLSID_GeometryDef);
ipGeoDef->put_GeometryType(esriGeometryPoint);
ipGeoDef->put_HasM(VARIANT_FALSE);
ipGeoDef->put_HasZ(VARIANT_FALSE);
ipGeoDef->putref_SpatialReference(pSpatialRef);
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SHAPE));
ipFieldEdit->put_IsNullable(VARIANT_TRUE);
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeoDef);
}
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add a Name field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_NAME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add a capacity field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_CAP));
ipFieldEdit->put_Type(esriFieldTypeDouble); // it use to be String. Have to be careful when I'm reading numbers from this field
ipFieldEdit->put_DefaultValue(ATL::CComVariant(-1.0));
ipFieldEdit->put_IsNullable(VARIANT_FALSE);
ipFieldsEdit->AddField(ipFieldEdit);
// Add the NALocation fields
AddLocationFields(ipFieldsEdit, pDENDS);
// Add the new fields to the class definition (these must be set before setting field types)
ipClassDefEdit->putref_Fields(ipFields);
// Setup the field types (i.e., input/output fields, editable/non-editable fields, visible/non-visible fields, or a combination of these)
AddLocationFieldTypes(ipClassDefEdit);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_OID), esriNAFieldTypeInput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SHAPE), esriNAFieldTypeInput | esriNAFieldTypeNotEditable | esriNAFieldTypeNotVisible);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_NAME), esriNAFieldTypeInput);
// Setup whether the NAClass is considered as input/output
ipClassDefEdit->put_IsInput(VARIANT_TRUE);
ipClassDefEdit->put_IsOutput(VARIANT_FALSE);
// Setup necessary cardinality for allowing a Solve to be run
// NOTE: the LowerBound property is used to define the minimum number of required NALocationObjects that are required by the solver
// to perform analysis. The UpperBound property is used to define the maximum number of NALocationObjects that are allowed by the solver
// to perform analysis.
// In our case, we must have at least one zone point stored in the class before allowing Solve to enabled in ArcMap, and we have no UpperBound
ipClassDefEdit->put_LowerBound(1);
// Give the class definition a name...
ipClassDefEdit->put_Name(ATL::CComBSTR(CS_ZONES_NAME));
// ...and add it to the named set
ipClassDefinitions->Add(ATL::CComBSTR(CS_ZONES_NAME), (IUnknownPtr)ipClassDef);
//******************************************************************************************/
// Evacuee Points class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriNetworkAnalyst.NALocationFeature")))) return hr;
ipClassDefEdit->putref_ClassCLSID(ipIUID);
// Create the fields for the class definition
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
// Create and add an OID field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add an population field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_EVC_POP2));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(1.0));
ipFieldEdit->put_IsNullable(VARIANT_FALSE);
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add a Shape field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
{
IGeometryDefEditPtr ipGeoDef(CLSID_GeometryDef);
ipGeoDef->put_GeometryType(esriGeometryPoint);
ipGeoDef->put_HasM(VARIANT_FALSE);
ipGeoDef->put_HasZ(VARIANT_FALSE);
ipGeoDef->putref_SpatialReference(pSpatialRef);
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SHAPE));
ipFieldEdit->put_IsNullable(VARIANT_TRUE);
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeoDef);
}
ipFieldsEdit->AddField(ipFieldEdit);
// Create and add a Name field
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_NAME));
ipFieldEdit->put_Type(esriFieldTypeString);
ipFieldEdit->put_Length(128);
ipFieldsEdit->AddField(ipFieldEdit);
// Add the NALocation fields
AddLocationFields(ipFieldsEdit, pDENDS);
// Add the new fields to the class definition (these must be set before setting field types)
ipClassDefEdit->putref_Fields(ipFields);
// Setup the field types (i.e., input/output fields, editable/non-editable fields, visible/non-visible fields, or a combination of these)
AddLocationFieldTypes(ipClassDefEdit);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_OID), esriNAFieldTypeInput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SHAPE), esriNAFieldTypeInput | esriNAFieldTypeNotEditable | esriNAFieldTypeNotVisible);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_NAME), esriNAFieldTypeInput);
// Setup whether the NAClass is considered as input/output
ipClassDefEdit->put_IsInput(VARIANT_TRUE);
ipClassDefEdit->put_IsOutput(VARIANT_FALSE);
// Setup necessary cardinality for allowing a Solve to be run
// NOTE: the LowerBound property is used to define the minimum number of required NALocationObjects that are required by the solver
// to perform analysis. The UpperBound property is used to define the maximum number of NALocationObjects that are allowed by the solver
// to perform analysis.
// In our case, we must have at least one Evacuee point stored in the class before allowing Solve to enabled in ArcMap, and we have no UpperBound
ipClassDefEdit->put_LowerBound(1);
// Give the class definition a name...
ipClassDefEdit->put_Name(ATL::CComBSTR(CS_EVACUEES_NAME));
// ...and add it to the named set
ipClassDefinitions->Add(ATL::CComBSTR(CS_EVACUEES_NAME), (IUnknownPtr)ipClassDef);
//******************************************************************************************/
// DynamicChanges class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriNetworkAnalyst.NALocationRangesFeature")))) return hr;
if (FAILED(hr = ipClassDefEdit->putref_ClassCLSID(ipIUID))) return hr;
// set up coded value domains for the the dynamic changes status values
ICodedValueDomainPtr ipCodedValueDomainEdgeDir(CLSID_CodedValueDomain), ipCodedValueDomainEvcStuck(CLSID_CodedValueDomain);
CreateEdgeDirCodedValueDomain(ipCodedValueDomainEdgeDir);
CreateEvcStuckCodedValueDomain(ipCodedValueDomainEvcStuck);
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
{
IGeometryDefEditPtr ipGeoDef(CLSID_GeometryDef);
ipGeoDef->put_GeometryType(esriGeometryPolygon);
ipGeoDef->put_HasM(VARIANT_FALSE);
ipGeoDef->put_HasZ(VARIANT_FALSE);
ipGeoDef->putref_SpatialReference(pSpatialRef);
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SHAPE));
ipFieldEdit->put_IsNullable(VARIANT_TRUE);
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeoDef);
}
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(L"Locations"));
ipFieldEdit->put_Type(esriFieldTypeBlob);
ipFieldEdit->put_Required(VARIANT_TRUE);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNROADDIR));
ipFieldEdit->put_Type(esriFieldTypeInteger);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(static_cast<long>(EdgeDirection::Both)));
ipFieldEdit->putref_Domain((IDomainPtr)ipCodedValueDomainEdgeDir);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNSTARTTIME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(0.0));
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNENDTIME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(-1.0));
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNCOST));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(10.0));
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNCAPACITY));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldEdit->put_DefaultValue(ATL::CComVariant(1.0));
ipFieldsEdit->AddField(ipFieldEdit);
//ipField.CreateInstance(CLSID_Field);
//ipFieldEdit = ipField;
//ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_DYNEVCSTUCK));
//ipFieldEdit->put_Type(esriFieldTypeInteger);
//ipFieldEdit->put_DefaultValue(ATL::CComVariant(long(1)));
//ipFieldEdit->putref_Domain((IDomainPtr)ipCodedValueDomainEvcStuck);
//ipFieldsEdit->AddField(ipFieldEdit);
ipClassDefEdit->putref_Fields(ipFields);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_OID), esriNAFieldTypeInput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SHAPE), esriNAFieldTypeInput | esriNAFieldTypeNotEditable | esriNAFieldTypeNotVisible);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(L"Locations"), esriNAFieldTypeInput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNROADDIR), esriNAFieldTypeInput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNSTARTTIME), esriNAFieldTypeInput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNENDTIME), esriNAFieldTypeInput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNCOST), esriNAFieldTypeInput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNCAPACITY), esriNAFieldTypeInput);
// ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_DYNEVCSTUCK), esriNAFieldTypeInput);
ipClassDefEdit->put_IsInput(VARIANT_TRUE);
ipClassDefEdit->put_IsOutput(VARIANT_FALSE);
ipClassDefEdit->put_Name(ATL::CComBSTR(CS_DYNCHANGES_NAME));
ipClassDefinitions->Add(ATL::CComBSTR(CS_DYNCHANGES_NAME), (IUnknownPtr)ipClassDef);
//******************************************************************************************/
// Flocks class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriGeoDatabase.Feature")))) return hr;
ipClassDefEdit->putref_ClassCLSID(ipIUID);
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
{
IGeometryDefEditPtr ipGeoDef(CLSID_GeometryDef);
ipGeoDef->put_GeometryType(esriGeometryPoint);
ipGeoDef->put_HasM(VARIANT_FALSE);
ipGeoDef->put_HasZ(VARIANT_FALSE);
ipGeoDef->putref_SpatialReference(pSpatialRef);
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SHAPE));
ipFieldEdit->put_IsNullable(VARIANT_TRUE);
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeoDef);
}
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_NAME));
ipFieldEdit->put_Type(esriFieldTypeString);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_ID));
ipFieldEdit->put_Type(esriFieldTypeInteger);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_COST));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_VelocityX));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_VelocityY));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SPEED));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_TRAVELED));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_TIME));
ipFieldEdit->put_Type(esriFieldTypeString);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_PTIME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_STATUS));
ipFieldEdit->put_Type(esriFieldTypeString);
ipFieldEdit->put_Length(1);
// set up coded value domains for the the flocking status values
ICodedValueDomainPtr ipCodedValueDomain(CLSID_CodedValueDomain);
CreateFlockingCodedValueDomain(ipCodedValueDomain);
ipFieldEdit->putref_Domain((IDomainPtr)ipCodedValueDomain);
ipFieldsEdit->AddField(ipFieldEdit);
ipClassDefEdit->putref_Fields(ipFields);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_OID), esriNAFieldTypeOutput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SHAPE), esriNAFieldTypeOutput | esriNAFieldTypeNotEditable | esriNAFieldTypeNotVisible);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_ID), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_NAME), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_VelocityX), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_VelocityY), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SPEED), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_TRAVELED), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_TIME), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_PTIME), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_STATUS), esriNAFieldTypeOutput);
ipClassDefEdit->put_IsInput(VARIANT_FALSE);
ipClassDefEdit->put_IsOutput(VARIANT_TRUE);
ipClassDefEdit->put_Name(ATL::CComBSTR(CS_FLOCKS_NAME));
ipClassDefinitions->Add(ATL::CComBSTR(CS_FLOCKS_NAME), (IUnknownPtr)ipClassDef);
//******************************************************************************************/
// Routes class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriGeoDatabase.Feature")))) return hr;
ipClassDefEdit->putref_ClassCLSID(ipIUID);
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
{
IGeometryDefEditPtr ipGeoDef(CLSID_GeometryDef);
ipGeoDef->put_GeometryType(esriGeometryPolyline);
ipGeoDef->put_HasM(VARIANT_FALSE);
ipGeoDef->put_HasZ(VARIANT_FALSE);
ipGeoDef->putref_SpatialReference(pSpatialRef);
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_SHAPE));
ipFieldEdit->put_IsNullable(VARIANT_TRUE);
ipFieldEdit->put_Type(esriFieldTypeGeometry);
ipFieldEdit->putref_GeometryDef(ipGeoDef);
}
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_RID));
ipFieldEdit->put_Type(esriFieldTypeInteger);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_EVC_NAME));
ipFieldEdit->put_Type(esriFieldTypeString);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_E_TIME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_E_ORG));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_EVC_POP2));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_ZONENAME));
ipFieldEdit->put_Type(esriFieldTypeDouble);
ipFieldsEdit->AddField(ipFieldEdit);
ipClassDefEdit->putref_Fields(ipFields);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_OID), esriNAFieldTypeOutput | esriNAFieldTypeNotEditable);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_SHAPE), esriNAFieldTypeOutput | esriNAFieldTypeNotEditable | esriNAFieldTypeNotVisible);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_EVC_NAME), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_E_TIME), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_EVC_POP2), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_E_ORG), esriNAFieldTypeOutput);
ipClassDefEdit->put_FieldType(ATL::CComBSTR(CS_FIELD_ZONENAME), esriNAFieldTypeOutput);
ipClassDefEdit->put_IsInput(VARIANT_FALSE);
ipClassDefEdit->put_IsOutput(VARIANT_TRUE);
ipClassDefEdit->put_Name(ATL::CComBSTR(CS_ROUTES_NAME));
ipClassDefinitions->Add(ATL::CComBSTR(CS_ROUTES_NAME), (IUnknownPtr)ipClassDef);
//******************************************************************************************/
// EdgeStat class definition
ipClassDef.CreateInstance(CLSID_NAClassDefinition);
ipClassDefEdit = ipClassDef;
ipIUID.CreateInstance(CLSID_UID);
if (FAILED(hr = ipIUID->put_Value(ATL::CComVariant(L"esriGeoDatabase.Feature")))) return hr;
ipClassDefEdit->putref_ClassCLSID(ipIUID);
ipFields.CreateInstance(CLSID_Fields);
ipFieldsEdit = ipFields;
ipField.CreateInstance(CLSID_Field);
ipFieldEdit = ipField;
ipFieldEdit->put_Name(ATL::CComBSTR(CS_FIELD_OID));
ipFieldEdit->put_Type(esriFieldTypeOID);
ipFieldsEdit->AddField(ipFieldEdit);