本文整理汇总了C++中Network类的典型用法代码示例。如果您正苦于以下问题:C++ Network类的具体用法?C++ Network怎么用?C++ Network使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Network类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Network yarp;
if (!yarp.checkNetwork())
{
yError("YARP server not available!");
return 1;
}
ResourceFinder rf;
rf.setDefaultContext("fingersTuner");
rf.setDefaultConfigFile("config.ini");
rf.configure(argc,argv);
TunerModule mod;
return mod.runModule(rf);
}
示例2: main
int main(int argc, char *argv[])
{
Network yarp;
if (!yarp.checkNetwork())
{
yError("Yarp network doesn't seem to be available!");
return -1;
}
ResourceFinder rf;
rf.setDefaultContext("iol2opc");
rf.setDefaultConfigFile("config.ini");
rf.configure(argc,argv);
IOL2OPCBridge bridge;
return bridge.runModule(rf);
}
示例3: main
int main(int argc, char *argv[])
{
Network yarp;
if (!yarp.checkNetwork())
return 1;
ResourceFinder rf;
rf.setVerbose(true);
rf.setDefaultContext("himrep");
rf.setDefaultConfigFile("sparseCoder.ini");
rf.configure(argc,argv);
rf.setDefault("name","sparseCoder");
SparseCoderModule mod;
return mod.runModule(rf);
}
示例4: indexList
void ContextMenuActionProvider::addIrcUserActions(QMenu *menu, const QModelIndex &index)
{
// this can be called: a) as a nicklist context menu (index has IrcUserItemType)
// b) as a query buffer context menu (index has BufferItemType and is a QueryBufferItem)
// c) right-click in a query chatview (same as b), index will be the corresponding QueryBufferItem)
// d) right-click on some nickname (_contextItem will be non-null, _filter -> chatview, index -> message buffer)
if (contextItem().isNull()) {
// cases a, b, c
bool haveQuery = indexList().count() == 1 && findQueryBuffer(index).isValid();
NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt());
addAction(_nickModeMenuAction, menu, itemType == NetworkModel::IrcUserItemType);
addAction(_nickCtcpMenuAction, menu);
IrcUser *ircUser = qobject_cast<IrcUser *>(index.data(NetworkModel::IrcUserRole).value<QObject *>());
if (ircUser) {
Network *network = ircUser->network();
// only show entries for usermode +h if server supports it
if (network && network->prefixModes().contains('h')) {
action(NickHalfop)->setVisible(true);
action(NickDehalfop)->setVisible(true);
}
else {
action(NickHalfop)->setVisible(false);
action(NickDehalfop)->setVisible(false);
}
// ignoreliststuff
QString bufferName;
BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
if (bufferInfo.type() == BufferInfo::ChannelBuffer)
bufferName = bufferInfo.bufferName();
QMap<QString, bool> ignoreMap = Client::ignoreListManager()->matchingRulesForHostmask(ircUser->hostmask(), ircUser->network()->networkName(), bufferName);
addIgnoreMenu(menu, ircUser->hostmask(), ignoreMap);
// end of ignoreliststuff
}
menu->addSeparator();
addAction(NickQuery, menu, itemType == NetworkModel::IrcUserItemType && !haveQuery && indexList().count() == 1);
addAction(NickSwitchTo, menu, itemType == NetworkModel::IrcUserItemType && haveQuery);
menu->addSeparator();
addAction(NickWhois, menu, true);
}
else if (!contextItem().isEmpty() && messageFilter()) {
// case d
// TODO
}
}
示例5: TEST
TEST(CoordinatorTest, MultipleAppends)
{
const std::string path1 = utils::os::getcwd() + "/.log1";
const std::string path2 = utils::os::getcwd() + "/.log2";
utils::os::rmdir(path1);
utils::os::rmdir(path2);
Replica replica1(path1);
Replica replica2(path2);
Network network;
network.add(replica1.pid());
network.add(replica2.pid());
Coordinator coord(2, &replica1, &network);
{
Result<uint64_t> result = coord.elect(Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(0, result.get());
}
for (uint64_t position = 1; position <= 10; position++) {
Result<uint64_t> result =
coord.append(utils::stringify(position), Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(position, result.get());
}
{
Future<std::list<Action> > actions = replica1.read(1, 10);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(10, actions.get().size());
foreach (const Action& action, actions.get()) {
ASSERT_TRUE(action.has_type());
ASSERT_EQ(Action::APPEND, action.type());
EXPECT_EQ(utils::stringify(action.position()), action.append().bytes());
}
}
utils::os::rmdir(path1);
utils::os::rmdir(path2);
}
示例6:
const Error *Node::UnInit( void )
{
// Detach this node from the network
if( netRef )
{
Network *net = (Network*)RefObj::LockRef( netRef );
if( net )
{
net->DetachNode( this );
net->UnlockRef();
}
RefObj::ReleaseRef( netRef );
netRef = 0;
}
return 0;
}
示例7: KNCube
Network * Network::NewNetwork(const Configuration & config, const string & name)
{
const string topo = config.GetStr( "topology" );
Network * n = NULL;
if ( topo == "torus" ) {
KNCube::RegisterRoutingFunctions() ;
n = new KNCube( config, name, false );
} else if ( topo == "mesh" ) {
KNCube::RegisterRoutingFunctions() ;
n = new KNCube( config, name, true );
} else if ( topo == "cmesh" ) {
CMesh::RegisterRoutingFunctions() ;
n = new CMesh( config, name );
} else if ( topo == "fly" ) {
KNFly::RegisterRoutingFunctions() ;
n = new KNFly( config, name );
} else if ( topo == "qtree" ) {
QTree::RegisterRoutingFunctions() ;
n = new QTree( config, name );
} else if ( topo == "tree4" ) {
Tree4::RegisterRoutingFunctions() ;
n = new Tree4( config, name );
} else if ( topo == "fattree" ) {
FatTree::RegisterRoutingFunctions() ;
n = new FatTree( config, name );
} else if ( topo == "flatfly" ) {
FlatFlyOnChip::RegisterRoutingFunctions() ;
n = new FlatFlyOnChip( config, name );
} else if ( topo == "anynet"){
AnyNet::RegisterRoutingFunctions() ;
n = new AnyNet(config, name);
} else if ( topo == "dragonflynew"){
DragonFlyNew::RegisterRoutingFunctions() ;
n = new DragonFlyNew(config, name);
} else {
cerr << "Unknown topology: " << topo << endl;
}
/*legacy code that insert random faults in the networks
*not sure how to use this
*/
if ( n && ( config.GetInt( "link_failures" ) > 0 ) ) {
n->InsertRandomFaults( config );
}
return n;
}
示例8: main
int main(int argc, char *argv[]) {
printf("This test creates two ports and writes from one to the other.\n");
printf("Make sure no other YARP programs are running.\n");
printf("(or else remove the yarpNetworkSetLocalMode line)\n");
Network yarp;
yarp.setLocalMode(1);
Port p1, p2;
bool ok = p1.open("/test1") && p2.open("/test2");
if (!ok) {
printf("failed to open ports\n");
return 1;
}
ok = yarp.connect("/test1","/test2",NULL);
if (!ok) {
printf("failed to connect ports\n");
return 1;
}
p1.enableBackgroundWrite(true);
MyPortable i1, i2;
i1.val = 15;
printf("Writing (in background)...\n");
p1.write(i1);
printf("Reading...\n");
p2.read(i2);
printf("After read, received %d\n", i2.val);
if (i2.val==15) {
printf("Correct!\n");
} else {
printf("That's not right, something failed.\n");
return 1;
}
p1.close();
p2.close();
return 0;
}
示例9: main
int main(int argc, char *argv[])
{
Network yarp;
if (!yarp.checkNetwork())
return -1;
YARP_REGISTER_DEVICES(icubmod)
ResourceFinder rf;
rf.setVerbose(true);
rf.setDefaultContext("sceneFlowModule");
rf.configure(argc,argv);
sceneFlowModule mod;
return mod.runModule(rf);
}
示例10: receiveMe
void receiveMe(const std::string &ip, int port, const std::string &dir, void (*cb)(int, void*), void *data) {
Network net;
FILE *file;
char *buff;
int received;
int i = 0, odoSize;
ANetwork::t_frame frame;
bool reading = true;
try {
net.init(port, ANetwork::TCP_MODE);
net.connect(ip);
net.write(CreateRequest::create(1, 2, 3, "File"));
frame = net.read();
odoSize = atoi(frame.data);
frame = net.read();
file = fopen(std::string(dir + frame.data).c_str(), "wb");
while (reading) {
buff = (char*) net.getSocket()->read(D_BUF, &received);
if (received <= 0)
break;
i += fwrite(buff, 1, received, file);
cb(i * 100 / odoSize, data);
}
fclose(file);
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
}
};
示例11: _backPropogation
/**
*
* ~~~~~ Back Propogation ~~~~~
*
* Train the network by 'back propogation'
* see http://en.wikipedia.org/wiki/Backpropagation
*/
std::vector<double> _backPropogation ( std::vector<double> input, std::vector<double> expected, Network& net )
{
// get the result of feeding the input into the network
std::vector<double> output = net.feedForward(input);
ActFunction actf = net.activate();
double rate = net.rate();
// ~~~~~ loop backwards over the layers ~~~~~
//
// as we descend though the layers, the difference between the output and the expected
// result is propogated through each layer; while the change in weights (deltas) is computed
// on for each layer.
for(auto layer = net.rbegin(); layer != net.rend(); ++layer)
{
// input and output for each layer
std::vector<double> layer_input = (*layer)->getInput();
std::vector<double> layer_output = (*layer)->getOutput();
// iterate over the neurons in a vector
auto out = layer_output.begin();
for (auto neuron = (*layer)->begin(); neuron != (*layer)->end(); ++neuron, ++out)
{
// the output layer is handled a bit differently, as it can be compared directly with the
// expected answer
auto ex = expected.begin();
auto in = layer_input.begin();
for (auto weight = (*neuron).begin(); weight != (*neuron).end(); ++weight, ++in, ++ex )
{
// calculate the deltas of the weights
double delta = rate * ((*ex) - (*in)) * actf.dydx((*out)) * (*in);
(*weight) -= delta;
}
}
// propogate the expected value down the chain by
// recalculating the layer's output with the new weights
expected = (*layer)->feedForward( layer_input );
}
return expected;
}
示例12: main
int main(int argc, char *argv[]) {
Property config;
config.fromCommand(argc,argv);
Network yarp;
Port client_port;
std::string servername= config.find("server").asString().c_str();
client_port.open("/demo/client");
if (!yarp.connect("/demo/client",servername.c_str()))
{
std::cout << "Error! Could not connect to server " << servername << std::endl;
return -1;
}
Demo demo;
demo.yarp().attachAsClient(client_port);
PointD point;
point.x = 0;
point.y = 0;
point.z = 0;
PointD offset;
offset.x = 1;
offset.y = 2;
offset.z = 3;
std::cout << "== get_answer ==" << std::endl;
int answer=demo.get_answer();
std::cout << answer << std::endl;
std::cout<<"== add_one =="<<std::endl;
answer = demo.add_one(answer);
std::cout << answer << std::endl;
std::cout<<"== double_down =="<<std::endl;
answer = demo.double_down(answer);
std::cout << answer << std::endl;
std::cout<<"== add_point =="<<std::endl;
point = demo.add_point(point,offset);
std::cout<<("== done! ==\n");
return 0;
}
示例13: test2
void test2() {
using namespace Utility;
using namespace std;
using namespace ml;
typedef double T;
Timer<float> timer;
timer.start();
Network<T>* network = new Network<T>();
ILayer<T>* l1 = new Layer<T>(100);
ILayer<T>* l2 = new Layer<T>(200);
ILayer<T>* l3 = new Layer<T>(500);
ILayer<T>* l4 = new Layer<T>(10);
l1->setName("L1");
l2->setName("L2");
l3->setName("L3");
l4->setName("L4");
network->setInputLayer(l1);
network->connect(l1, l2);
network->connect(l2, l3);
network->connect(l3, l4);
network->setOutputLayer(l4);
network->init();
ml::Mat<T> samples(100, 100, 1);
ml::Mat<T> nominals(1, 10, 0);
network->train(samples, nominals);
timer.stop();
cout << timer.getTime() << endl;
}
示例14: main
int main(int argc,char** argv){
if (argc <= 1 || argc > 2)
{
std::cerr << "Please enter exactly one filename" << std::endl;
}else
{
Network n;
std::string file(argv[1]), name;
std::stringstream sfile(file);
std::getline(sfile,name,'.');
name = name + ".ieq" ;
n.init(argv[1]);
n.findSequences();
n.findSPC();
n.findWPC();
// n.printWPC();
// n.printControlArcs();
n.writePorta(name);
name = "matrix";
n.writeIncidenceMatrix(name);
}
return 0;
}
示例15: load_pajek_format_network
/*
* Modified from the Infomap implementation.
* Reading the given network data in Pajek format.
*/
void load_pajek_format_network(string fName, Network &network) {
string line;
string buf;
string nameBuf;
/* Read network in Pajek format with nodes ordered 1, 2, 3, ..., N, */
/* each directed link occurring only once, and link weights > 0. */
/* For more information, see http://vlado.fmf.uni-lj.si/pub/networks/pajek/. */
/* Node weights are optional and sets the relative proportion to which */
/* each node receives teleporting random walkers. Default value is 1. */
/* Example network with three nodes and four directed and weighted links: */
/* *Vertices 3 */
/* 1 "Name of first node" 1.0 */
/* 2 "Name of second node" 2.0 */
/* 3 "Name of third node" 1.0 */
/* *Arcs 4 */
/* 1 2 1.0 */
/* 1 3 1.7 */
/* 2 3 2.0 */
/* 3 2 1.2 */
cout << "Reading network " << fName << " file\n" << flush;
ifstream net(fName.c_str());
network.setNNode(0);
istringstream ss;
while(network.NNode() == 0){
if(getline(net,line) == NULL){
cout << "the network file is not in Pajek format...exiting" << endl;
exit(-1);
}
else{
ss.clear();
ss.str(line);
ss >> buf;
if(buf == "*Vertices" || buf == "*vertices" || buf == "*VERTICES"){
ss >> buf;
network.setNNode(atoi(buf.c_str()));
}
else{
cout << "the network file is not in Pajek format...exiting" << endl;
exit(-1);
}
}