Is there is a way to get the associated MN's to an access point? - c++

I'm using INET and want to simulate a scenario that consist of three Access Points (AP)and one Mobile Node (MN), may each AP has other associated MNs on its range, what I want is : while the MN (in my scenario) move around and get beacons from the APs, before association with APs can I get the number of other MNs that associated with each AP? I explored many source codes and I found MACaddressTable and something like that stalist in ieee80211MgmtAP ,are they useful for me? and use them as total Number of associated MNs,
then How can I evaluate the length of stalist? or MACaddressTable?
else I must put a counter to count that at on AP side and emit it through beacon frame? if so please give me some guides or shortcuts
regards ....

In IEEE 802.11 AP does not send information about the number of associated stations. Therefore in order to broadcast this information you have to introduce your own modification/extension into IEEE 802.11 protocols, for example a new field in beacon frame.
In INET model AP stores own stations in staList map. To locally calculate the current number of associated station you can use the following code:
STAList::const_iterator it;
int assocSta = 0;
for (it = staList.begin(); it != staList.end(); ++it) {
if (it->second.status == ASSOCIATED)
assocSta++;
}
If you want modify standard beacon frame, firstly, you have to assume where exactly you want to add a new field in beacon frame, e.g. after which existing field, as well as what size this filed should have. Then:
add a new filed (for example int noOfAssociatedStas;) in class Ieee80211BeaconFrameBody in file Ieee80211MgmtFrames.msg and correct length in Ieee80211BeaconFrame definition
in Ieee80211Serializer.cc after else if (dynamic_cast<const Ieee80211BeaconFrame *>(pkt)) add serialization of a new field, for example:
unsigned int numSta = Frame->getBody().getNoOfAssociatedStas();
b.writeByte(numSta); // assuming that the new field is 1 byte length
in Ieee80211Serializer.cc in deserialize add deserialization of a new field, after case 0x80: //ST_BEACON for example:
unsigned int numSta = b.readByte();
Please note that the place of adding the new filed (second bullet) must exactly match the place of reading it (third bullet).

Related

Algorithm Help for Directed Graph List

I have an assignment for my class where we are attempting to find the best (cheapest) path to a destination. The description is as follows:
Each tech has a name, a cost to buy that tech, a boolean saying whether or not the player has the tech already, and a list of 0 to N techs that are available for purchase when the player buys this tech. There are three categories of tech in Tactigo: Social, Military, and Science. Each of the three starts with a basic tech that the player must purchase before purchasing more advanced techs. These basic techs are special because they are always available for purchase.
Looking at the diagram, you will note that a few techs are unlocked by multiple techs. Remember that techs are unlocked as soon as ANY tech unlocks them. In other words, you need either "Being Nice to Animals" OR "Being a Dick to People" in order to buy "Attack Animal Training". You don't need both, just one. Your task is to find the cheapest way to get any given technology. The player might own any set of techs already, so you must account for that. For example, if the player already owns "Being Nice to People" and wants to find the cheapest way to get "Making Friends", the path returned should just be "Making Friends". They don't need to purchase anything else.
The Graph looks as follows:
I originally thought of doing a depth-first-search on each of the 3 categories while calculating the cost of each path taken. My Code for this function is as follows:
//---------------------------------------------------------------------------------------------------------------------
// This function finds the best path to the tech we want.
// * goalTech: The index of the tech we're looking for. Call GetTechByIndex() to get the actual Tech instance.
// * bestPath: The best path to the goal tech. This is an array sorted in the order of the best path from the
// start to the goal. This is an output variable; it's what you need to populate with this function.
//---------------------------------------------------------------------------------------------------------------------
void TechTree::FindBestPath(int goalTech, Path& bestPath)
{
//First ensure that best path is cleared out
bestPath.clear();
//Get Tech Instance for this Goal Tech
const Tech* pGoalTech = GetTechByIndex(goalTech);
//make sure we get a valid tech
assert(pGoalTech != nullptr);
//Check first if user already has this unlocked.
if (pGoalTech->HasTech())
{
//just return
return;
}
//Check if the goal tech is one of the three starting techs.
if (pGoalTech == GetBasicSocialTech()|| pGoalTech == GetBasicScienceTech() || pGoalTech == GetBasicMilitaryTech())
{
//now we know that one of the basic techs are the goal, so we just add one of those to the path
if (pGoalTech == GetBasicSocialTech())
bestPath.push_back(GetBasicSocialTech());
else if (pGoalTech == GetBasicMilitaryTech())
bestPath.push_back(GetBasicMilitaryTech());
else
bestPath.push_back(GetBasicScienceTech());
return; //now return
}
//my process will be as follows.
//1. Since all the edges are directed we need to traverse down three different graphs: Social (starting at index 0), Military (starting at index 4) and Science (starting at index 8)
//2. I am going to perform a depth-first search starting at Social and then moving down to Military and then Science.
//3. As I am performing a depth-first I am going to keep track of a path and its respective cost, if a search gets to the goal I will make sure to register that and then move onto the next graph.
//4. When there are no more paths to search I send the lowest cost one back.
///start with social at index 0
const Tech* pStartSocialTech = GetBasicSocialTech();
std::pair<int, std::vector<const Tech*>> bestCurrentPath;
//get starting cost for this category before we move into neighbors,
// if player already has this tech we set this to zero if not we get the cost of buying into this category
int startingCost = pStartSocialTech->HasTech() ? 0 : pStartSocialTech->GetCost();
/*pStartSocialNeighbors = get all neighbors for starting point at social
while (destination is not found AND there are more neighbors to pStartSocialNeighbors)
{
DFS(neighbor, dest) //if this finds the destination we store a path and its cost, otherwise it doesnt do anything and we move on to next basic tree
}
//do the same thing for military and science...
*/
}
I have a lot of comments on it but I am just wondering if this is the best route to take. Other options are Dijkstras or A* but I don't know how you would traverse the path of this directed graph. I am not looking for a direct answer since this is a homework assignment but I am looking for some guidance.
Thanks!
Going from the target to source using Dijkstras, you need to modify the stop condition if you want to stop before searching all paths. I don't see any heuristic for A* in this case.
Adding a node with a path to all known techs
You can now use Dijkstras / Bellman-Ford.
Using A* has the problem you need to find a heuristic that works. You could use depth times min cost of all edges. that requires you to already have traversed the graph to assign depth.

SCIP: How to resolve LP after catching a 'node infeasibility' event,

I have a working column generation algorithm in SCIP. Due to specific constraints that I include while generating columns, it might happen that the last pricing round determines that the root node is infeasible (by the Farkas pricer of course).
In case that happens, I would like to 1) relax those specific constraints, 2) resolve the LP, and 3) start pricing columns again.
So, I have created my own EventHandler class, catching the node infeasibility event:
SCIP_DECL_EVENTINITSOL(EventHandler::scip_initsol)
{
SCIP_CALL( SCIPcatchEvent(scip_, SCIP_EVENTTYPE_NODEINFEASIBLE, eventhdlr, NULL, NULL));
return SCIP_OKAY;
}
And, corresponding, the scip_exec virtual method:
SCIP_DECL_EVENTEXEC(EventHandler::scip_exec)
{
double cur_rhs = SCIPgetRhsLinear(scip_, *d_varConsInfo).c_primal_obj_cut);
SCIPchgRhsLinear (scip_, (*d_varConsInfo).c_primal_obj_cut, cur_rhs + DELTA);
return SCIP_OKAY;
}
Where (*d_varConsInfo).c_primal_obj_cut is the specific constraint to be changed, DELTA is a global parameter, and cur_rhs is the current right hand side of the specific constraint. This function is neately called after the node infeasibility proof, however, I do not know how to 'tell' scip that the LP should be resolved and possible new columns should be included. Can somebody help me out with this?
When the event handler catches the NODEINFEASIBLE event, it is already too late to change something about the infeasibility of the problem, the node processing is already finished. Additionally, you are not allowed to change the rhs of a constraint during the solving process (because this means that reductions done before would potentially be invalid).
I would suggest the following: if your Farkas pricing is not able to identify new columns to render the LP feasible again, the node will be declared to be infeasible in the following. Therefore, at the end of Farkas pricing (if you are at the root node), you could just price an auxiliary variable that you add to the constraint that you want to relax, with bounds corresponding to your DELTA. Note that you need to have marked the constraint to be modifiable when creating it. Then, since a variable was added, SCIP will trigger another pricing round.
maybe you should take a look into the PRICERFARKAS method of SCIP (https://scip.zib.de/doc/html/PRICER.php#PRICER_FUNDAMENTALCALLBACKS).
If the current LP relaxation is infeasible, it is the task of the
pricer to generate additional variables that can potentially render
the LP feasible again. In standard branch-and-price, these are
variables with positive Farkas values, and the PRICERFARKAS method
should identify those variables.

Adding weka instances after classification but before evaluation?

Suppose X is a raw, labeled (ie, with training labels) data set, and Process(X) returns a set of Y instances
that have been encoded with attributes and converted into a weka-friendly file like Y.arff.
Also suppose Process() has some 'leakage':
some instances Leak = X-Y can't be encoded consistently, and need
to get a default classification FOO. The training labels are also known for the Leak set.
My question is how I can best introduce instances from Leak into the
weka evaluation stream AFTER some classifier has been applied to the
subset Y, folding the Leak instances in with their default
classification label, before performing evaulation across the full set X? In code:
DataSource LeakSrc = new DataSource("leak.arff");
Instances Leak = LeakSrc.getDataSet();
DataSource Ysrc = new DataSource("Y.arff");
Instances Y = Ysrc.getDataSet();
classfr.buildClassifer(Y)
// YunionLeak = ??
eval.crossValidateModel(classfr, YunionLeak);
Maybe this is a specific example of folding together results
from multiple classifiers?
the bounty is closing, but Mark Hall, in another forum (
http://list.waikato.ac.nz/pipermail/wekalist/2015-November/065348.html) deserves what will have to count as the current answer:
You’ll need to implement building the classifier for the cross-validation
in your code. You can still use an evaluation object to compute stats for
your modified test folds though, because the stats it computes are all
additive. Instances.trainCV() and Instances.testCV() can be used to create
the folds:
http://weka.sourceforge.net/doc.stable/weka/core/Instances.html#trainCV(int,%20int,%20java.util.Random)
You can then call buildClassifier() to process each training fold, modify
the test fold to your hearts content, and then iterate over the instances
in the test fold while making use of either Evaluation.evaluateModelOnce()
or Evaluation.evaluateModelOnceAndRecordPrediction(). The later version is
useful if you need the area under the curve summary metrics (as these
require predictions to be retained).
http://weka.sourceforge.net/doc.stable/weka/classifiers/Evaluation.html#evaluateModelOnce(weka.classifiers.Classifier,%20weka.core.Instance)
http://weka.sourceforge.net/doc.stable/weka/classifiers/Evaluation.html#evaluateModelOnceAndRecordPrediction(weka.classifiers.Classifier,%20weka.core.Instance)
Depending on your classifier, it could be very easy! Weka has an interface called UpdateableClassifier, any class using this can be updated after it has been built! The following classes implement this interface:
HoeffdingTree
IBk
KStar
LWL
MultiClassClassifierUpdateable
NaiveBayesMultinomialText
NaiveBayesMultinomialUpdateable
NaiveBayesUpdateable
SGD
SGDText
It can then be updated something like the following:
ArffLoader loader = new ArffLoader();
loader.setFile(new File("/data/data.arff"));
Instances structure = loader.getStructure();
structure.setClassIndex(structure.numAttributes() - 1);
NaiveBayesUpdateable nb = new NaiveBayesUpdateable();
nb.buildClassifier(structure);
Instance current;
while ((current = loader.getNextInstance(structure)) != null) {
nb.updateClassifier(current);
}

WMQ C++ Get request's message id and set it correlation id for reply

I have a problem on getting message id and set it on reply's correlation id.
Here's the piece of code:
MQBYTE msgID;
request_msg.messageId().copyOut(msgID, MQ_MSG_ID_LENGTH, 0);
response_msg.setCorrelationId(msgID);
when I checked the correlation Id of the reply, the correlation id is 0.
How can I copy/get the messageId of the request and put it on the correlation id of the reply?
Thanks in advance. :)
The Infocenter page Manipulating binary strings in C++ shows the data types involved as ImqBinary and MQBYTE24. As Shashi notes in the comments, MQBYTE is a single byte and incapable of containing a 24-byte message ID. The page linked above provides a reference example:
#include <imqi.hpp> // C++ classes
ImqMessage message ;
ImqBinary id, correlationId ;
MQBYTE24 byteId ;
correlationId.set( byteId, sizeof( byteId ) ); // Set.
id = message.id( ); // Assign.
if ( correlationId == id ) { // Compare.
...
One tool to diagnose issues like this is the very useful SupportPac MA0W which is an API exit. It can show you the exact contents of the structures passed to MQ before and after an API call. Very often what is seen is that what is expected (in this case having copied the MQMD.MsgID to the MQMD.CorrelID is not what actually happened. In this case, I believe a trace such as that provided by MA0W would reveal that the msgID was accurately passed from the app to MQ but consisted of only one character.
UPDATE
OP asks:
Variable id is an ImqBinary and message is an ImqMessage
object, from what I know id is not a member of ImqMessage like
messageId, correlationId, groupId and etc. so how can
message.id() passed it's value on id?
You are coorrect that id is a declared variable of type ImqBinary and not a member of the ImqMessage class. Please see the Infocenter page for the ImqBinary C++ class which explains that:
This class encapsulates a binary byte array that can be used for
ImqMessage accounting token, correlation id, and message id values. It
allows easy assignment, copying, and comparison.
The intent of the ImqBinary class is to provide a variable type to encapsulate a byte array with overloaded methods such that "normal" variable manipulations work as expected. Rather than copying the byte array one byte at a time, it can be an LVAL or RVAL in an assignment. Rather than comparing the array a byte at a time, you can just use comparison operators like ==.
So if your code were modified to use the example, it might look like this:
#include <imqi.hpp> // C++ classes
ImqMessage request_msg, response_msg ;
ImqBinary id ;
id = request_msg.id( );
response_msg.setCorrelationId(id);
That said, I'm not sure you even need an intermediate variable. You might be able to assign the correlation ID using the output of the getter call for the message ID from the source message. Something like....
response_msg.setCorrelationId( request_msg.id( ) );
...might do it. I don't code C or C++ anymore so I probably got the syntax wrong or didn't do it as elegantly as it might be coded, but you should get the idea.

C++ - Where to store a global counter?

The diagram http://www.freeimagehosting.net/uploads/2fd3f4161c.png
Here's the Minimalist-UML diagram of an app I've been working on. It's supposed to simulate the management of a bunch of sensors relating to different measurements.
Please ignore the House class, the diagram is outdated...
However, I have trouble. Each sensor (sound, contact, heat, pressure, gas - All of these inherit from sensor) has an unique ID, starting at 0 for the first one and ending at the total number of sensors - 1.
For good practices' sake, where shall I store the total number of sensors, so the classes I'm using for input/output of files (saving and loading) and insertion of new sensors can access and increment that counter?
Thank you for your time!
One option would be to create a static function in your Sensor class that increments and returns a static counter variable. The constructor for Sensor could call this function to get an ID.
// header file
class Sensor
{
...
protected:
static int getId() { return id++; }
private:
static int id;
int myId;
};
// .cpp file
int Sensor::id = 0;
Sensor::Sensor(...)
: myId(getId())
...
{}
I'm ignoring threading and persistence issues here. But hopefully this gives you a better idea.
Whatever object creates the sensors should assign the identifiers to the sensors.
If multiple objects create sensors, then they should be assigned a pointer or reference to a provider of identifiers when they are created and they should query that provider for a new unique identifier as they create new sensor objects.
Your unique ID, like a database table ID will likely have some issues.
You will probably find, eventually, that your ID needs to persist across sessions--that your window's ID is used in some other relationship.
You may, some day, also find that it needs to be unique across multiple server/client sets.
I'm just suggesting that you should consider these issues off the bat.
As for where the ID should be generated, since all your "Sensor" classes inherit from one base class, I think I'd generate it via a threadsafe method in that base class--and I'd store it there as well.
what's the problem? do you use a Vector to store your sensors? define a Vector of holding sensor-objects in the house.
can access and increment that counter
you don't have to do this, the Vector does it for you
Have a look at the Singleton pattern assuming you don't want to do it with a database of some sort.