//transform dividends STDMETHODIMP CEtsHolidayAtom::TransformDividends(SAFEARRAY **psaDates, LONG nCount, SAFEARRAY **psaTDates, LONG *pnTCount) { if (!pnTCount || !psaDates || !psaTDates) return E_POINTER; HRESULT hr = S_OK; try { *pnTCount = 0; if (nCount > 0) { DOUBLE *pdDates = NULL; LongVector lvDates; if( *psaTDates ) { ::SafeArrayDestroy(*psaTDates); *psaTDates = NULL; } if( SUCCEEDED(hr = ::SafeArrayAccessData(*psaDates, reinterpret_cast<void**>(&pdDates))) ) { DATE dtRealDate; for(int i = 0; i < nCount; i++) { GetPreviousWorkingDate(DATE(pdDates[i] * 365.0), &dtRealDate); lvDates.push_back( static_cast<LONG>(floor(dtRealDate)) ); } ::SafeArrayUnaccessData(*psaDates); *pnTCount = static_cast<LONG>(lvDates.size()); if (*pnTCount > 0) { LPSAFEARRAY pDates = SafeArrayCreateVector(VT_R8, 0, *pnTCount); ::SafeArrayLock(pDates); LPVOID lpDateData = NULL; ::SafeArrayAccessData(pDates, &lpDateData); DOUBLE * pdDates = reinterpret_cast<DOUBLE *>(lpDateData); for(long i = 0; i< *pnTCount; i++) { pdDates[i] = lvDates[i]/365.0; } ::SafeArrayUnaccessData(pDates); ::SafeArrayUnlock(pDates); *psaTDates = pDates; } } } } catch (...) { return E_FAIL; } return S_OK; }
// ------------------------------------------------------------------------- int GraphDefinition:: my_dijkstra(edge_t *edges, unsigned int edge_count, int start_vertex, int end_vertex, bool directed, bool has_reverse_cost, path_element_t **path, int *path_count, char **err_msg, std::vector<PDVI> &ruleList) { m_ruleTable.clear(); int total_rule = ruleList.size(); int i; LongVector vecsource; unsigned int kk; for(i = 0; i < total_rule; i++) { Rule rule; rule.cost = ruleList[i].first; int j; int seq_cnt = ruleList[i].second.size(); for(j = 1; j < seq_cnt; j++) { rule.precedencelist.push_back(ruleList[i].second[j]); } int dest_edge_id = ruleList[i].second[0]; if(m_ruleTable.find(dest_edge_id) != m_ruleTable.end()) { m_ruleTable[dest_edge_id].push_back(rule); } else { std::vector<Rule> temprules; temprules.clear(); temprules.push_back(rule); m_ruleTable.insert(std::make_pair(dest_edge_id, temprules)); } if(isStartVirtual) { if(seq_cnt == 2 && ruleList[i].second[1] == m_lStartEdgeId) { vecsource = m_mapNodeId2Edge[start_vertex]; for(kk = 0; kk < vecsource.size(); kk++) { rule.precedencelist.clear(); rule.precedencelist.push_back(m_vecEdgeVector[vecsource[kk]]->m_lEdgeID); m_ruleTable[dest_edge_id].push_back(rule); } } } } if(isEndVirtual) { if(m_ruleTable.find(m_lEndEdgeId) != m_ruleTable.end()) { std::vector<Rule> tmpRules = m_ruleTable[m_lEndEdgeId]; vecsource = m_mapNodeId2Edge[end_vertex]; for(kk = 0; kk < vecsource.size(); kk++) { m_ruleTable.insert(std::make_pair(m_vecEdgeVector[vecsource[kk]]->m_lEdgeID, tmpRules)); } } } m_bIsturnRestrictOn = true; return(my_dijkstra(edges, edge_count, start_vertex, end_vertex, directed, has_reverse_cost, path, path_count, err_msg)); }
ModelTreeDialog::ModelTreeDialog(HINSTANCE hInstance, HWND hParentWindow): CUIDialog(hInstance, hParentWindow), m_modelWindow(NULL), m_model(NULL), m_modelTree(NULL), m_resizer(NULL), m_optionsShown(true), m_highlight(TCUserDefaults::boolForKey(MODEL_TREE_HIGHLIGHT_KEY, false, false)), m_clearing(false) { COLORREF defHighlightColor = RGB(160, 224, 255); long highlightColor = TCUserDefaults::longForKey(MODEL_TREE_HIGHLIGHT_COLOR_KEY, defHighlightColor, false); LongVector customColors; customColors = TCUserDefaults::longVectorForKey(MODEL_TREE_CUST_COLORS_KEY, customColors, false); if (customColors.size() == 0) { // Put the default highlight color into the list of custom colors. customColors.resize(16); customColors[0] = defHighlightColor; TCUserDefaults::setLongVectorForKey(customColors, MODEL_TREE_CUST_COLORS_KEY, false); } m_highlightR = GetRValue(highlightColor); m_highlightG = GetGValue(highlightColor); m_highlightB = GetBValue(highlightColor); TCAlertManager::registerHandler(ModelWindow::alertClass(), this, (TCAlertCallback)&ModelTreeDialog::modelAlertCallback); }
// ------------------------------------------------------------------------- void GraphDefinition::explore( int cur_node, GraphEdgeInfo& cur_edge, bool isStart, LongVector &vecIndex, std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > &que) { unsigned int i; double extCost = 0.0; GraphEdgeInfo* new_edge; // int new_node; double totalCost; for(i = 0; i < vecIndex.size(); i++) { new_edge = m_vecEdgeVector[vecIndex[i]]; extCost = 0.0; if(m_bIsturnRestrictOn) { extCost = getRestrictionCost(cur_edge.m_lEdgeIndex, *new_edge, isStart); } if(new_edge->m_lStartNode == cur_node) { if(new_edge->m_dCost >= 0.0) { //new_node = new_edge->m_lEndNode; if(isStart) totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + new_edge->m_dCost + extCost; else totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + new_edge->m_dCost + extCost; if(totalCost < m_dCost[vecIndex[i]].endCost) { m_dCost[vecIndex[i]].endCost = totalCost; parent[new_edge->m_lEdgeIndex].v_pos[0] = (isStart?0:1); parent[new_edge->m_lEdgeIndex].ed_ind[0] = cur_edge.m_lEdgeIndex; que.push(std::make_pair(totalCost, std::make_pair(new_edge->m_lEdgeIndex, true))); } } } else { if(new_edge->m_dReverseCost >= 0.0) { // new_node = new_edge->m_lStartNode; if(isStart) totalCost = m_dCost[cur_edge.m_lEdgeIndex].endCost + new_edge->m_dReverseCost + extCost; else totalCost = m_dCost[cur_edge.m_lEdgeIndex].startCost + new_edge->m_dReverseCost + extCost; if(totalCost < m_dCost[vecIndex[i]].startCost) { m_dCost[vecIndex[i]].startCost = totalCost; parent[new_edge->m_lEdgeIndex].v_pos[1] = (isStart?0:1); parent[new_edge->m_lEdgeIndex].ed_ind[1] = cur_edge.m_lEdgeIndex; que.push(std::make_pair(totalCost, std::make_pair(new_edge->m_lEdgeIndex, false))); } } } } }
void Foo_A_Statistics::actual_in_values(unsigned op_num, LongVector lv) { size_t sz = lv.size(); for (size_t i = 0; i < sz; i++) { this->actual_in_values_[op_num-1].push_back (lv[i]); } }
void sort ( LongVector & vector ) { unsigned size = vector.size (); if (size > 0) { unsigned indexOfMin; unsigned pass; unsigned j; for ( pass = 0; pass < size - 1; pass++ ) { indexOfMin = pass; for ( j = pass + 1; j < size; j++ ) if ( vector[j] < vector[indexOfMin] ) indexOfMin = j; swap ( vector[pass], vector[indexOfMin] ); } } }
// ------------------------------------------------------------------------- int GraphDefinition:: my_dijkstra(edge_t *edges, unsigned int edge_count, int start_vertex, int end_vertex, bool directed, bool has_reverse_cost, path_element_t **path, int *path_count, char **err_msg) { if(!m_bIsGraphConstructed) { init(); construct_graph(edges, edge_count, has_reverse_cost, directed); m_bIsGraphConstructed = true; } std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que; parent = new PARENT_PATH[edge_count + 1]; m_dCost = new CostHolder[edge_count + 1]; m_vecPath.clear(); unsigned int i; for(i = 0; i <= edge_count; i++) { m_dCost[i].startCost = 1e15; m_dCost[i].endCost = 1e15; } if(m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end()) { *err_msg = (char *)"Source Not Found"; deleteall(); return -1; } if(m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end()) { *err_msg = (char *)"Destination Not Found"; deleteall(); return -1; } LongVector vecsource = m_mapNodeId2Edge[start_vertex]; GraphEdgeInfo* cur_edge = NULL; for(i = 0; i < vecsource.size(); i++) { cur_edge = m_vecEdgeVector[vecsource[i]]; if(cur_edge->m_lStartNode == start_vertex) { if(cur_edge->m_dCost >= 0.0) { m_dCost[cur_edge->m_lEdgeIndex].endCost= cur_edge->m_dCost; parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1; parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1; que.push(std::make_pair(cur_edge->m_dCost, std::make_pair(cur_edge->m_lEdgeIndex, true))); } } else { if(cur_edge->m_dReverseCost >= 0.0) { m_dCost[cur_edge->m_lEdgeIndex].startCost = cur_edge->m_dReverseCost; parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1; parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1; que.push(std::make_pair(cur_edge->m_dReverseCost, std::make_pair(cur_edge->m_lEdgeIndex, false))); } } } //parent[start_vertex].v_id = -1; //parent[start_vertex].ed_id = -1; //m_dCost[start_vertex] = 0.0; // int new_node; int cur_node = -1; while(!que.empty()) { PDP cur_pos = que.top(); que.pop(); int cured_index = cur_pos.second.first; cur_edge = m_vecEdgeVector[cured_index]; //GraphEdgeInfo* new_edge; if(cur_pos.second.second) // explore edges connected to end node { cur_node = cur_edge->m_lEndNode; if(cur_edge->m_dCost < 0.0) continue; if(cur_node == end_vertex) break; explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge, que); } else // explore edges connected to start node { cur_node = cur_edge->m_lStartNode; if(cur_edge->m_dReverseCost < 0.0) continue; if(cur_node == end_vertex) break; explore(cur_node, *cur_edge, false, cur_edge->m_vecStartConnectedEdge, que); } } if(cur_node != end_vertex) { if(m_lStartEdgeId == m_lEndEdgeId) { if(get_single_cost(1000.0, path, path_count)) { return 0; } } *err_msg = (char *)"Path Not Found"; deleteall(); return -1; } else { double total_cost; if(cur_node == cur_edge->m_lStartNode) { total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost; construct_path(cur_edge->m_lEdgeIndex, 1); } else { total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost; construct_path(cur_edge->m_lEdgeIndex, 0); } path_element_t pelement; pelement.vertex_id = end_vertex; pelement.edge_id = -1; pelement.cost = 0.0; m_vecPath.push_back(pelement); if(m_lStartEdgeId == m_lEndEdgeId) { if(get_single_cost(total_cost, path, path_count)) { return 0; } } *path = (path_element_t *) malloc(sizeof(path_element_t) * (m_vecPath.size() + 1)); *path_count = m_vecPath.size(); for(int i = 0; i < *path_count; i++) { (*path)[i].vertex_id = m_vecPath[i].vertex_id; (*path)[i].edge_id = m_vecPath[i].edge_id; (*path)[i].cost = m_vecPath[i].cost; } if(isStartVirtual) { (*path)[0].vertex_id = -1; (*path)[0].edge_id = m_lStartEdgeId; } if(isEndVirtual) { *path_count = *path_count - 1; (*path)[*path_count - 1].edge_id = m_lEndEdgeId; } } deleteall(); return 0; }
// ------------------------------------------------------------------------- int GraphDefinition::my_dijkstra(int start_vertex, int end_vertex, unsigned int edge_count, char **err_msg) { if(!m_bIsGraphConstructed) { *err_msg = (char *)"Graph not Ready!"; return -1; } unsigned int i; for(i = 0; i <= edge_count; i++) { m_dCost[i].startCost = 1e15; m_dCost[i].endCost = 1e15; } if(m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end()) { *err_msg = (char *)"Source Not Found"; deleteall(); return -1; } if(m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end()) { *err_msg = (char *)"Destination Not Found"; deleteall(); return -1; } std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que; LongVector vecsource = m_mapNodeId2Edge[start_vertex]; GraphEdgeInfo* cur_edge = NULL; for(i = 0; i < vecsource.size(); i++) { cur_edge = m_vecEdgeVector[vecsource[i]]; if(cur_edge->m_lStartNode == start_vertex) { if(cur_edge->m_dCost >= 0.0) { m_dCost[cur_edge->m_lEdgeIndex].endCost= cur_edge->m_dCost; parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1; parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1; que.push(std::make_pair(cur_edge->m_dCost, std::make_pair(cur_edge->m_lEdgeIndex, true))); } } else { if(cur_edge->m_dReverseCost >= 0.0) { m_dCost[cur_edge->m_lEdgeIndex].startCost = cur_edge->m_dReverseCost; parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1; parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1; que.push(std::make_pair(cur_edge->m_dReverseCost, std::make_pair(cur_edge->m_lEdgeIndex, false))); } } } // int new_node; int cur_node = -1; while(!que.empty()) { PDP cur_pos = que.top(); que.pop(); int cured_index = cur_pos.second.first; cur_edge = m_vecEdgeVector[cured_index]; //GraphEdgeInfo* new_edge; if(cur_pos.second.second) // explore edges connected to end node { cur_node = cur_edge->m_lEndNode; if(cur_edge->m_dCost < 0.0) continue; if(cur_node == end_vertex) break; explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge, que); } else // explore edges connected to start node { cur_node = cur_edge->m_lStartNode; if(cur_edge->m_dReverseCost < 0.0) continue; if(cur_node == end_vertex) break; explore(cur_node, *cur_edge, false, cur_edge->m_vecStartConnectedEdge, que); } } if(cur_node != end_vertex) { *err_msg = (char *)"Path Not Found"; deleteall(); return -1; } else { // double total_cost; //set but not used if(cur_node == cur_edge->m_lStartNode) { // total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost; construct_path(cur_edge->m_lEdgeIndex, 1); } else { // total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost; construct_path(cur_edge->m_lEdgeIndex, 0); } path_element_t pelement; pelement.vertex_id = end_vertex; pelement.edge_id = -1; pelement.cost = 0.0; m_vecPath.push_back(pelement); } return 0; }