the_index() { list.push_back(stock("TEA",COMMON_STOCK,0.00,0, 1.00)); list.push_back(stock("POP",COMMON_STOCK,0.08,0, 1.00)); list.push_back(stock("ALE",COMMON_STOCK,0.23,0, 0.60)); list.push_back(stock("GIN",PREF_STOCK,0.08,2, 1.00)); list.push_back(stock("JOE",COMMON_STOCK,0.13,0, 2.50)); }
int main() { LocalStocks stock("Ticker.dat"); TenObserver t_observer("Change10.dat"); AverageObserver a_observer("Average.dat"); AllObserver l_observer("Selection2.dat"); if(stock.addObserver(&a_observer) == -1) { std::cout << "failure" << std::endl; std::exit(1); } if(stock.addObserver(&t_observer) == -1) { std::cout << "failure" << std::endl; std::exit(1); } if(stock.addObserver(&l_observer) == -1) { std::cout << "failure" << std::endl; std::exit(1); } stock.execute(); }
int StockTable::totalStock() { int total = 0; for(int row = 0; row < rowCount(); row++) total += stock(row); return total; }
void surf3::operator=( const surf3 &surf ) { tick(); dump(">>> Copying surface mesh...\n"); gm = surf.gm; if( surf.surf == &surf.bccsurf ) { this->surf = &bccsurf; bccsurf = surf.bccsurf; } else if( surf.surf == &surf.meshsurf ) { this->mesh = surf.mesh; this->surf = &meshsurf; tick(); dump("Copying mesh surface..."); meshsurf = surf.meshsurf; meshsurf.setReference(&mesh); dump("Done. Took %s.\n",stock()); } else if( surf.surf == &surf.cellsurf ) { this->surf = &cellsurf; cellsurf = surf.cellsurf; } dump("<<< Done. Took %s.\n",stock()); }
int main() { try { // its in one big try block Connection con(use_exceptions); con.connect("mysql_cpp_data"); Query query = con.query(); query << "select * from stock"; set<stock> res; query.storein(res); // here we are storing the elements in a set not a vector. cout.setf (ios::left); cout << setw (17) << "Item" << setw (4) << "Num" << setw (7) << "Weight" << setw (7) << "Price" << "Date" << endl << endl; // Now we we iterate through the set. Since it is a set the list will // naturally be in order. set<stock>::iterator i; cout.precision(3); for (i = res.begin (); i != res.end (); i++) { cout << setw (17) << i->item.c_str () << setw (4) << i->num << setw (7) << i->weight << setw (7) << i->price << i->sdate << endl; } i = res.find(stock("Hamburger Buns")); if (i != res.end()) cout << "Hamburger Buns found. Currently " << i->num << " in stock.\n"; else cout << "Sorry no Hamburger Buns found in stock\n"; // Now we are using the set's find method to find out how many // Hamburger Buns are in stock. return 0; } catch (BadQuery er) { cerr << "Error: " << er.error << endl; return -1; } catch (BadConversion er) { cerr << "Error: Tried to convert \"" << er.data << "\" to a \"" << er.type_name << "\"." << endl; return -1; } }
void surf3::buildSurface(const fluid3 *fluidSolver, const levelset3 *fluid, const levelset3 *solid, bool enclose ) { tick(); dump(">>> Building surfaces started...\n"); if( fluidSolver->getBCCMesh() ) { surf = &bccsurf; bccsurf.setBCC(*fluidSolver->getBCCMesh()); bccsurf.buildSurface(vertices,normals,faces,fluid,solid,enclose); } else if( fluidSolver->getMesh() ) { surf = &meshsurf; mesh = *fluidSolver->getMesh(); meshsurf.setReference(&mesh); meshsurf.buildSurface(vertices,normals,faces,fluid,solid,enclose); } else { surf = &cellsurf; cellsurf.buildSurface(vertices,normals,faces,fluid,solid,enclose); } // Build ANN tick(); dump("Building ANN structure for mesh vertices..."); ann.sort(vertices); dump("Done. Took %s.\n", stock("surf_ANN")); // Compute vertices to face info v2f.clear(); v2f.resize(vertices.size()); for( uint n=0; n<faces.size(); n++ ) { for( uint m=0; m<DIM; m++ ) { v2f[faces[n][m]].push_back(n); } } dump("<<< Done. Took %s.\n",stock("surf_build")); tick(); dump("Computing mesh-based curvature (%d vertices %d faces)...", vertices.size(), faces.size()); computeCurvature(solid); dump("Done. Took %s.\n", stock("surf_curvature")); // Write some info writeNumber("surf_vertex_num", vertices.size()); writeNumber("surf_face_num", faces.size()); }
void PolylinesRenderer::InitializeGL() { StockResources stock(GetResources()); geom_ = GetResources()->MakeGeometry(); material_ = stock.NewMaterial(StockResources::kPerVertexColorNoLighting); // Draw fat thick lines. material_->SetLineWidth(10.0f); draw_node_ = GetScene()->MakeDrawNode(GetBaseNode(), geom_, material_); UpdateGeometry(); }
void meshsurf3::fillHoles( std::vector<FLOAT64> &values, const levelset3 *solid, const std::vector<vec3d> &nodes, const std::vector<std::vector<uint> > &elements, const std::vector<std::vector<uint> > &node2node, FLOAT64 dx ) { // Simple hack to fix check-mark artifacts tick(); dump("Filling holes on solid wall"); uint count_filled = 0; for( uint k=0; k<3; k++ ) { std::vector<bool> adjacentFlag(nodes.size()); std::vector<FLOAT64> old_levelset = values; PARALLEL_FOR for( uint n=0; n<values.size(); n++ ) { bool connected_wall = false; if( solid->evalLevelset(nodes[n]) > -dx ) { for( uint m=0; m<node2node[n].size(); m++ ) { if( solid->evalLevelset(nodes[node2node[n][m]]) < dx ) { connected_wall = true; break; } } } adjacentFlag[n] = connected_wall; } PARALLEL_FOR for( uint n=0; n<nodes.size(); n++ ) { if( adjacentFlag[n] && old_levelset[n] > 0.0 ) { uint fluid_count = 0; uint non_fluid_count = 0; FLOAT64 avg = 0.0; FLOAT64 sum = 0.0; for( uint m=0; m<node2node[n].size(); m++ ) { uint idx = node2node[n][m]; if( adjacentFlag[idx] ) { if( old_levelset[idx] < 0.0 ) { fluid_count ++; avg += old_levelset[idx]; sum ++; } else { non_fluid_count ++; } } } if( sum && fluid_count > 2*non_fluid_count ) { values[n] = avg / sum; count_filled ++; } } } dump("."); } dump("Done. Took %s. Filled %d holes.\n",stock("meshsurf_fill_hole"), count_filled ); writeNumber("meshsurf_fill_hole_number", count_filled); }
t_tetri *get_tetri(char *entry, t_tetri *tab) { int i; int fd; char buf[1]; fd = open(entry, O_RDONLY); i = 1; tab[0].str = stock(fd, 0); tab[0].last = -1; while (read(fd, buf, 1)) { if (*buf != '\n') error("Error\n"); tab[i].str = stock(fd, i); tab[i].last = -1; i++; if (i > 26) error("Error\n"); } close(fd); check(tab[0].str); return (tab); }
void Factory::deliverGood() { // make a cart pusher and send him away StringHelper::debug( 0xff, "Good is ready!!!" ); if( _mayDeliverGood() ) { GoodStock stock(_outGoodType, 100, 100); CartPusherPtr walker = CartPusher::create( BuildingPtr( this ), stock ); walker->send2City(); _d->progress -= 100.f; if( !walker->isDeleted() ) _addWalker( walker.as<Walker>() ); } }
void GoodsUpdater::timeStep(const unsigned int time) { if( game::Date::isWeekChanged() ) { _d->isDeleted = (_d->endTime < game::Date::current()); Logger::warning( "GoodsUpdater: execute service" ); BuildingList buildings = _city()->statistic().objects.find<Building>( _d->buildings ); for( auto building : buildings ) { good::Stock stock( _d->gtype, _d->value, _d->value ); building->storeGoods( stock, _d->value ); } } }
int main() { struct goods *head=NULL; int x,y,z,a,b,c; do { printf("欢迎使用商品库存信息管理系统!\n1. 输入商品信息2. 销售3. 进货4. 列举商品信息5. 清除所有商品6. 退出\n请输入您的选择:"); scanf("%d",&x); if(x==1) { head=create(); printf("\n"); } if(x==2) { printf("请输入商品号和销售数量(以逗号分隔):"); scanf("%d,%d",&y,&z); head=sell(y,z); printf("\n"); } if(x==3) { printf("请输入商品号和进货数量(以逗号分隔):"); scanf("%d,%d",&a,&b); head=stock(a,b); printf("\n"); } if(x==4) { list(head); printf("\n"); } if(x==5) { printf("确认清除输入1,否则输入0:"); scanf("%d",&c); if(c==1) { destroy(head); head=NULL; } printf("\n"); } }while(x!=6); printf("\n"); return 0; }
TilePos getWalkerDestination2( Propagator &pathPropagator, const TileOverlayType type, MarketPtr market, SimpleGoodStore& basket, const Good::Type what, PathWay &oPathWay, long& reservId ) { SmartPtr< T > res; Propagator::Routes pathWayList; pathPropagator.getRoutes(type, pathWayList); int max_qty = 0; // select the warehouse with the max quantity of requested goods for( Propagator::Routes::iterator pathWayIt= pathWayList.begin(); pathWayIt != pathWayList.end(); ++pathWayIt) { // for every warehouse within range BuildingPtr building= pathWayIt->first; PathWay& pathWay= pathWayIt->second; SmartPtr< T > destBuilding = building.as< T >(); int qty = destBuilding->getGoodStore().getMaxRetrieve( what ); if( qty > max_qty ) { res = destBuilding; oPathWay = pathWay; max_qty = qty; } } if( res.isValid() ) { // a warehouse/granary has been found! // reserve some goods from that warehouse/granary int qty = std::min( max_qty, market->getGoodDemand( what ) ); qty = std::min(qty, basket.getMaxQty( what ) - basket.getCurrentQty( what )); // std::cout << "MarketLady reserves from warehouse, qty=" << qty << std::endl; GoodStock stock( what, qty, qty); reservId = res->getGoodStore().reserveRetrieval( stock ); return res->getTilePos(); } return TilePos(-1, -1); }
/* -------------------------- */ static int order(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset, int big) { guint8 value; offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); value = tvb_get_guint8(tvb, offset); col_append_fstr(pinfo->cinfo, COL_INFO, "%c ", value); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_buy_sell, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big); offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big); return offset; }
void DrawContext::DrawBoundingBox(const AxisAlignedBox& box) { if (!bounding_box_node_) { StockResources stock(resources_); ShaderResource::Ptr shader = stock.Shader(StockResources::kUniformColorNoLighting); MaterialResource::Ptr material = resources_->MakeMaterial(shader); material->SetParam("color", 0.0f, 1.0f, 0.0f, 1.0f); GeometryResource::Ptr geometry = resources_->MakeGeometry(); GeometryData gdata; gdata.gl_mode = GL_LINES; gdata.vertices = { { QVector3D(0, 0, 0) }, { QVector3D(0, 1, 0) }, { QVector3D(1, 1, 0) }, { QVector3D(1, 0, 0) }, { QVector3D(0, 0, 1) }, { QVector3D(0, 1, 1) }, { QVector3D(1, 1, 1) }, { QVector3D(1, 0, 1) }, }; gdata.indices = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; geometry->Load(gdata); bounding_box_node_ = scene_->MakeDrawNode(nullptr); bounding_box_node_->Add(geometry, material); // hack to prevent the bounding box to appear during normal rendering bounding_box_node_->SetVisible(false); } bounding_box_node_->SetScale(box.Max() - box.Min()); bounding_box_node_->SetTranslation(box.Min()); model_mat_ = bounding_box_node_->WorldTransform(); DrawDrawNode(bounding_box_node_); }
void DataFeed(std::istream& in, OutFiles& outs) { DataIn in_container; while (in >> in_container) { std::string stock(in_container.stock_name, 8); std::ofstream& out = outs[stock]; if (!out.is_open()) { std::string out_name(BINARY_DIR "/output_"); out_name.append(stock); out_name.append(".txt"); out.open(out_name, std::ios::binary); } if (out.good()) { out << DataOutStream(in_container); } } };
void StockShapeRenderer::InitializeGL() { Scene::Ptr scene = GetScene(); ResourceManager::Ptr resources = GetResources(); GroupNode* base_node = GetBaseNode(); // Create a material to share among several shapes StockResources stock(resources); material_ = stock.NewMaterial(StockResources::kUniformColorLighting); material_->SetParam(sv::kDiffuse, 1.0, 0.5, 0.5, 1.0); material_->SetParam(sv::kSpecular, 1.0, 0.5, 0.5, 1.0); material_->SetParam(sv::kShininess, 10.0f); // Create a material to use for the selected shape select_material_ = stock.NewMaterial(StockResources::kUniformColorLighting); select_material_->SetParam(sv::kDiffuse, 1.0, 0.0, 1.0, 1.0); select_material_->SetParam(sv::kSpecular, 1.0, 0.0, 0.1, 1.0); select_material_->SetParam(sv::kShininess, 16.0f); // Create a bunch of shapes shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cone(), material_)); shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cube(), material_)); shapes_.push_back(scene->MakeDrawNode(base_node, stock.Cylinder(), material_)); shapes_.push_back(scene->MakeDrawNode(base_node, stock.Sphere(), material_)); DrawNode* axes = scene->MakeDrawNode(base_node); axes->Add(stock.UnitAxes()); shapes_.push_back(axes); // Move the shapes so they're not all on top of each other. // // Also set the selection mask for each node so that they can be selected by // StockShapeSelector const double spacing = 2.0; const double x_start = - spacing * shapes_.size() / 2; for (size_t i = 0; i < shapes_.size(); ++i) { shapes_[i]->SetTranslation(x_start + i * spacing, 0, 0); shapes_[i]->SetSelectionMask(1); } }
std::list<Stock> DBAccess::GetStocksFromDatabase() { std::list<Stock> stockList; mysqlpp::Query query = m_connection.query("SELECT sid, ticker FROM %0;"); query.parse(); if ( mysqlpp::StoreQueryResult result = query.store(m_stockTable) ) { for (size_t i = 0; i < result.num_rows(); i++) { Stock stock((int)result[i]["sid"],(std::string)result[i]["ticker"]); stockList.push_front(stock); } } else { std::cerr << "Query to retrieve stocks failed. " << query.error() << "\n"; exit(1); } return(stockList); }
void Granary::_tryDevastateGranary() { //if granary in devastation mode need try send cart pusher with goods to other granary/warehouse/factory for( int goodType=Good::wheat; goodType <= Good::vegetable; goodType++ ) { int goodQty = math::clamp( goodQty, 0, 400); if( goodQty > 0 ) { GoodStock stock( (Good::Type)goodType, goodQty, goodQty); CartPusherPtr walker = CartPusher::create( _getCity() ); walker->send2City( BuildingPtr( this ), stock ); if( !walker->isDeleted() ) { stock._currentQty = 0; _d->goodStore.retrieve( stock, goodQty );//setCurrentQty( (GoodType)goodType, goodQtyMax - goodQty ); addWalker( walker.as<Walker>() ); break; } } } }
void House::buyMarket( ServiceWalkerPtr walker ) { // std::cout << "House buyMarket" << std::endl; MarketPtr market = walker->getBase().as<Market>(); GoodStore& marketStore = market->getGoodStore(); GoodStore &houseStore = getGoodStore(); for (int i = 0; i < G_MAX; ++i) { GoodType goodType = (GoodType) i; int houseQty = houseStore.getCurrentQty(goodType); int houseSafeQty = _d->houseLevelSpec.computeMonthlyConsumption(*this, goodType) + _d->nextHouseLevelSpec.computeMonthlyConsumption(*this, goodType); int marketQty = marketStore.getCurrentQty(goodType); if (houseQty < houseSafeQty && marketQty > 0) { int qty = std::min(houseSafeQty - houseQty, marketQty); GoodStock stock(goodType, qty); marketStore.retrieve(stock, qty); houseStore.store(stock, qty); } } }
int main(){ char name[20]; int qty,rate,amt,ch; stock(40); riskyTabs(restyl,avil); pf("\nAvailable medicines\n"); pf("1.Headache\n"); pf("2.Cold\n"); pf("3.Sleeping tabs\n"); pf("4.EXIT\n\n"); scanf("%d",&ch ); switch(ch){ case 1: headache; bill; break; case 2: cold; bill; break; case 3: sleeping; bill; case 4: return(0); break; } pf("enter your choice "); if(strcmp(name,"restyl")==0){ pf("Sorry.As you require a powerful tab,Please come back with doctor's prescription\n"); } else{ go; amt=qty*rate; pf("The total bill amount for %s is %d\n",name,amt); } }
int main(int argc, char **argv) { int fd; static t_p *f; fd = 0; if (!argv[1]) { ft_putstr_fd("No file\n", 2); return (-1); } if (argc != 2) return (-1); f = malloc(sizeof(t_p)); fd = open(argv[1], O_RDONLY); if (fd == -1) bad_file(); f = size_m(f, argv); f = stock(f, fd); f = window(f); f = convint(f); fdf(f); return (0); }
/* ---------------------------- */ static void dissect_nasdaq_itch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_item *ti; proto_tree *nasdaq_itch_tree = NULL; guint8 nasdaq_itch_type; int offset = 0; gint col_info; int version = 3; int big = 0; col_info = PINFO_COL(pinfo); col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-ITCH"); nasdaq_itch_type = tvb_get_guint8(tvb, offset); if (nasdaq_itch_type >= '0' && nasdaq_itch_type <= '9') { version = 2; nasdaq_itch_type = tvb_get_guint8(tvb, offset +8); } if ((!nasdaq_itch_chi_x || version == 3) && strchr(chix_msg, nasdaq_itch_type)) { nasdaq_itch_type = 0; /* unknown */ } if (col_info || tree) { const gchar *rep = val_to_str(nasdaq_itch_type, message_types_val, "Unknown packet type (0x%02x) "); if (col_info ) { col_clear(pinfo->cinfo, COL_INFO); col_add_str(pinfo->cinfo, COL_INFO, rep); } if (tree) { proto_item *item; ti = proto_tree_add_protocol_format(tree, proto_nasdaq_itch, tvb, offset, -1, "Nasdaq TotalView-ITCH %s, %s", version == 2?"2.0":"3.0", rep); nasdaq_itch_tree = proto_item_add_subtree(ti, ett_nasdaq_itch); item=proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_version, tvb, 0, 0, version); PROTO_ITEM_SET_GENERATED(item); } } if (version == 2) { offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 8); } proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message_type, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; if (version == 3) { switch (nasdaq_itch_type) { case 'T': /* seconds */ offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_second, offset, 5); return; case 'M': /* milliseconds */ offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 3); return; } } switch (nasdaq_itch_type) { case 'S': /* system event */ proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_system_event, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; break; case 'R': /* Stock Directory */ offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_market_category, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_financial_status, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lot_size, tvb, offset, 6, ENC_ASCII|ENC_NA); offset += 6; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lots_only, tvb, offset, 1, ENC_BIG_ENDIAN); offset += 1; break; case 'H': /* Stock trading action */ offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_trading_state, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reserved, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reason, tvb, offset, 4, ENC_ASCII|ENC_NA); offset += 4; break; case 'a' : big = 1; case 'A': /* Add order, no MPID */ offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); if (version == 2) { proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; } break; case 'F': /* Add order, MPID */ offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_attribution, tvb, offset, 4, ENC_ASCII|ENC_NA); offset += 4; break; case 'e' : big = 1; case 'E' : /* Order executed */ offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big); break; case 'C' : /* Order executed with price */ offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_execution_price, offset, big); break; case 'x' : big = 1; case 'X' : /* Order cancel */ offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_canceled, offset, big); break; case 'D' : /* Order delete */ offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset); offset += 9; break; case 'p' : big = 1; case 'P' : /* Trade identifier */ offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA); offset += 9; break; case 'Q' : /* Cross Trade */ offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big); offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA); offset += 9; proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; break; case 'B' : /* Broken Trade */ proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA); offset += 9; break; case 'I': /* NOII, FIXME */ offset = stock(tvb, pinfo, nasdaq_itch_tree, offset); proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA); offset += 1; break; default: /* unknown */ proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message, tvb, offset, -1, ENC_ASCII|ENC_NA); offset += 5-1; break; } }
int main () { int prices[] = {15, 6, 3, 2, 8, 10, 3, 2, 5}; printf ("Max gains = %d.\n", stock (prices, sizeof(prices)/sizeof(prices[0]))); return 0; }
Docker::Docker( PlayerCityPtr city ) : CartPusher( city ) { _setType( walker::docker ); stock().setCapacity( bigCart ); }
meshsurf3::meshsurf3( const meshsurf3 &meshsurf ) { tick(); dump("Copying mesh surf..."); *this = meshsurf; dump("Done. Took %s.\n",stock()); }
void meshsurf3::buildSurface( std::vector<vec3d> &vertices, std::vector<vec3d> &normals, std::vector<vec3i> &faces, const levelset3 *fluid, const levelset3 *solid, bool enclose, FLOAT64 dpx, uint iteration, bool doFit ) { // Save a reference to the mesher const mesher3 &g = *this->g; tick(); dump("Computing levelset for %d nodes...", g.nodes.size()); values.clear(); values.resize(g.nodes.size()); if( values.empty() ) { email::print("Mesher Uninitialized !\n"); email::send(); exit(0); } // Compute levelset for each node PARALLEL_FOR for( uint n=0; n<g.nodes.size(); n++ ) { FLOAT64 phi = fluid->evalLevelset(g.nodes[n]); if( enclose ) phi = fmax(phi,-dpx-solid->evalLevelset(g.nodes[n])); values[n] = phi; } dump("Done. Took %s.\n",stock("meshsurf_levelset_sample")); // Fill holes fillHoles(values,solid,g.nodes,g.elements,g.node2node,fluid->dx); // Calculate intersections on edges tick(); dump("Computing cut edges for each tet..."); std::vector<vec3d> cutpoints(g.edges.size()); std::vector<int> cutIndices(g.edges.size()); uint index = 0; for( int n=0; n<g.edges.size(); n++ ) { FLOAT64 levelsets[2]; for( uint m=0; m<2; m++ ) levelsets[m] = values[g.edges[n][m]]; if( copysign(1.0,levelsets[0]) * copysign(1.0,levelsets[1]) <= 0 ) { FLOAT64 det = levelsets[0]-levelsets[1]; if( fabs(det) < 1e-16 ) det = copysign(1e-16,det); FLOAT64 a = fmin(0.99,fmax(0.01,levelsets[0]/det)); vec3d p = (1.0-a)*g.nodes[g.edges[n][0]]+a*g.nodes[g.edges[n][1]]; cutpoints[n] = p; cutIndices[n] = index++; } else { cutIndices[n] = -1; } } // Copy them to packed array vertices.clear(); vertices.resize(index); index = 0; for( uint n=0; n<cutIndices.size(); n++ ) { if( cutIndices[n] >= 0 ) vertices[index++] = cutpoints[n]; } dump("Done. Took %s.\n",stock()); // Stitch faces (marching tet) tick(); dump("Stitching edges..."); std::vector<std::vector<uint> > node_faces; node_faces.resize(g.nodes.size()); faces.clear(); for( uint n=0; n<g.elements.size(); n++ ) { std::vector<uint> nv; for( uint m=0; m<g.element_edges[n].size(); m++ ) { uint idx = g.element_edges[n][m]; if( cutIndices[idx] >= 0 ) { nv.push_back(cutIndices[idx]); } } if( nv.size() == 4 ) { // Triangulate the veritces int idx0 = -1; int idx1 = -1; for( uint m=0; m<g.element_edges[n].size(); m++ ) { if( cutIndices[g.element_edges[n][m]] >= 0 ) { idx0 = g.element_edges[n][m]; break; } } // If found one intersection edge if( idx0 >= 0 ) { for( uint m=0; m<g.element_edges[n].size(); m++ ) { uint opID = g.element_edges[n][m]; if( cutIndices[opID] >= 0 && isOpEdge(idx0,opID)) { idx1 = opID; break; } } // If found opposite intersection edge if( idx1 >= 0 ) { vec3i v; v[0] = cutIndices[idx0]; v[1] = cutIndices[idx1]; for( uint m=0; m<g.element_edges[n].size(); m++ ) { uint idx2 = g.element_edges[n][m]; if( cutIndices[idx2] >= 0 && idx2 != idx0 && idx2 != idx1 ) { v[2] = cutIndices[idx2]; faces.push_back(v); for( uint m=0; m<g.elements[n].size(); m++ ) { node_faces[g.elements[n][m]].push_back(faces.size()-1); } } } } else { dump( "Opposite edge was not found !\n"); exit(0); } } else { dump( "Ground edge was not found !\n"); exit(0); } } else if( nv.size() == 3 ) { faces.push_back(vec3i(nv[0],nv[1],nv[2])); for( uint m=0; m<g.elements[n].size(); m++ ) { node_faces[g.elements[n][m]].push_back(faces.size()-1); } } else if( nv.size() == 0 ) { // Empty surface. Do nothing... } else { dump( "\nBad stitch encounrtered: Element - edge count = %d.\n", g.element_edges[n].size() ); dump( "Unknown set found N(%e,%e,%e,%e) = %d.\n", values[g.elements[n][0]], values[g.elements[n][1]], values[g.elements[n][2]], values[g.elements[n][3]], nv.size()); for( uint k=0; k<g.element_edges[n].size(); k++ ) { uint vidx[2] = { g.edges[g.element_edges[n][k]][0], g.edges[g.element_edges[n][k]][1] }; dump( "Edge info[%d] = edge(%d,%d) = (%e,%e) = (%f,%f)\n", k, vidx[0], vidx[1], values[vidx[0]], values[vidx[1]], copysign(1.0,values[vidx[0]]), copysign(1.0,values[vidx[1]]) ); } } } dump("Done. Took %s.\n",stock("meshsurf_stitch_mesh")); // Find closest position tick(); dump("Finding closest surface position at surface tets..."); surfacePos.clear(); surfacePos.resize(g.nodes.size()); for( uint n=0; n<g.nodes.size(); n++ ) { FLOAT64 dist = 1e8; vec3d p = g.nodes[n]; for( uint m=0; m<node_faces[n].size(); m++ ) { vec3d p0 = vertices[faces[node_faces[n][m]][0]]; vec3d p1 = vertices[faces[node_faces[n][m]][1]]; vec3d p2 = vertices[faces[node_faces[n][m]][2]]; vec3d out = g.nodes[n]; vec3d src = out; FLOAT64 d = fmax(1e-8,point_triangle_distance(src,p0,p1,p2,out)); if( d < dist ) { p = out; dist = d; } } if( dist < 1.0 ) { values[n] = (values[n]>=0 ? 1.0 : -1.0) * dist; surfacePos[n].push_back(g.nodes[n]); surfacePos[n].push_back(p); } else { values[n] = (values[n]>=0 ? 1.0 : -1.0) * 1e8; } } dump("Done. Took %s.\n",stock("meshsurf_find_close_pos1")); if( extrapolate_dist ) { // Fast march tick(); std::vector<fastmarch3<FLOAT64>::node3 *> fnodes(g.nodes.size()); for( uint n=0; n<g.nodes.size(); n++ ) fnodes[n] = new fastmarch3<FLOAT64>::node3; for( uint n=0; n<g.nodes.size(); n++ ) { vec3d p = g.nodes[n]; bool fixed = fabs(values[n]) < 1.0; fnodes[n]->p = p; fnodes[n]->fixed = fixed; fnodes[n]->levelset = values[n]; fnodes[n]->value = 0.0; fnodes[n]->p2p.resize(g.node2node[n].size()); for( uint m=0; m<g.node2node[n].size(); m++ ) { fnodes[n]->p2p[m] = fnodes[g.node2node[n][m]]; } } fastmarch3<FLOAT64>::fastMarch(fnodes,extrapolate_dist,-extrapolate_dist,1); // Pick up values for( uint n=0; n<g.nodes.size(); n++ ) { values[n] = fnodes[n]->levelset; delete fnodes[n]; } stock("meshsurf_fastmarch"); } // Compute normal tick(); dump("Computing normals..."); computeNormals(vertices,normals,faces,cutIndices); dump("Done. Took %s.\n",stock("meshsurf_normal")); // Flip facet rotation if necessary flipFacet(vertices,normals,faces,0.1*fluid->dx); #if 1 // Fit surface if( doFit ) { tick(); dump("Fitting %d surface vertices...", vertices.size() ); for( uint k=0; k<1; k++ ) { smoothMesh(vertices,normals,faces,solid,dpx,1); PARALLEL_FOR for( uint n=0; n<vertices.size(); n++ ) { vec3d out = vertices[n]; if( solid->evalLevelset(out) > dpx && fluid->getClosestSurfacePos(out) ) { vertices[n] = out; } } } dump("Done. Took %s.\n",stock("meshsurf_fit")); } #endif // Smooth mesh #if 1 tick(); dump("Smoothing faces..."); smoothMesh(vertices,normals,faces,solid,dpx,iteration); dump("Done. Took %s.\n",stock("meshsurf_smooth")); #endif // Find closest position again tick(); dump("Finding closest surface position at surface tets again..."); surfacePos.clear(); surfacePos.resize(g.nodes.size()); for( uint n=0; n<g.nodes.size(); n++ ) { FLOAT64 dist = 1e8; vec3d p = g.nodes[n]; for( uint m=0; m<node_faces[n].size(); m++ ) { vec3d p0 = vertices[faces[node_faces[n][m]][0]]; vec3d p1 = vertices[faces[node_faces[n][m]][1]]; vec3d p2 = vertices[faces[node_faces[n][m]][2]]; vec3d out = g.nodes[n]; vec3d src = out; FLOAT64 d = fmax(1e-8,point_triangle_distance(src,p0,p1,p2,out)); if( d < dist ) { p = out; dist = d; } } if( dist < 1.0 ) { values[n] = (values[n]>=0 ? 1.0 : -1.0) * dist; } } dump("Done. Took %s.\n",stock("meshsurf_find_close_pos2")); // Flip again flipFacet(vertices,normals,faces,0.1*fluid->dx); }