How to find the most matched values in the set of map?

Hi friends!
I have two vectors
vector<int> V1; vector<int> V2;
and a map<int, set<int>> M1;
I want to select common values from both V1 and V2 and check those values with the set in the map M1.
For example:
V1 contains;
2  4  6  8  9
V2 contains;
4  5  6  9  10 
M1 contains;
1=>1  2  5  9
2=>4
3=>5   10
4=>2  4  8
5=>4   9
6=>4   6
7=>9  12
When we select the common values of V1 and V2 it is 4, 6, 9.
And we search for all 4, 6, 9 from the values of M1 which give more appropriate.
But, no all values in the set of map.
Then, we delete any value from 4, 6, 9, then remaining values would match any values from the map.
From the example, if we delete 6, then remaining 4, 9 will match with 5=>4  9, or if we delete 9, then 6=>4   6. Any one of the keys can be selected.
I know how to select the common values from V1 and V2, but I do not know how to match with the values and select the appropriate key from M1.
Could anyone help me to solve this?

This is not the question you asked, except perhaps in the subject. The subject is not the right place to put key features of the question. It is also important to use the body to ask just the question you want
answered. For example your real question has nothing to do with V1 and V2, just the common vector V (e.g. 4 6 9).
One way to solve your problem would be to create a new map
map<int, set<int>> M2;
with the same keys as M1. Each set of M2 should contain the elements of V that are
not in the corresponding set of M1.
Then pick the key of M2 that has the smallest set. If that set is empty, then the whole of V can be used. Otherwise the smallest set tells which elements of V have to be removed, and which is the desired key of M1.
In your example, key 5 of M2 will contain just 6, so you should remove 6 from V and select key 5.
Yes fine. I tried the following code and it creates the map M2 (NewMyMap in my code). But how to find the smallest set starting from size 1?
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef vector<int> IntVec;
typedef set<int> IntSet;
typedef map<int, IntSet> SetMap;
bool IsValueNotInSet(int value, IntSet& S);
SetMap CreatNewSetMap();
IntVec IVec; //This vector is for selecting certain keys from mySet map.
IntVec myVec;
SetMap mySet;
SetMap NewMyMap;
int main()
IVec.push_back(3); IVec.push_back(4); IVec.push_back(5); IVec.push_back(6);
myVec.push_back(4); myVec.push_back(6); myVec.push_back(9);
IntSet tempS;
tempS.insert(1); tempS.insert(2); tempS.insert(5); tempS.insert(9);
mySet.insert(make_pair(1,tempS));
tempS.clear();
tempS.insert(4);
mySet.insert(make_pair(2,tempS));
tempS.clear();
tempS.insert(5); tempS.insert(10);
mySet.insert(make_pair(3,tempS));
tempS.clear();
tempS.insert(2); tempS.insert(4); tempS.insert(8);
mySet.insert(make_pair(4,tempS));
tempS.clear();
tempS.insert(4); tempS.insert(9);
mySet.insert(make_pair(5,tempS));
tempS.clear();
tempS.insert(4); tempS.insert(6);
mySet.insert(make_pair(6,tempS));
tempS.clear();
tempS.insert(9); tempS.insert(12);
mySet.insert(make_pair(7,tempS));
cout<<"MYVEC\n";
cout<<"-------------\n";
for(IntVec::iterator itv = myVec.begin(); itv != myVec.end(); ++itv)
cout<<(*itv)<<" ";
cout<<"\n\n";
cout<<"\nMYSET\n";
cout<<"-------------";
for(map<int,set<int>>::iterator its = mySet.begin(); its != mySet.end(); ++its)
cout << endl << its->first <<" =>";
for(IntSet::iterator sit=its->second.begin();sit!=its->second.end();++sit)
cout<<" "<<(*sit);
cout<<"\n\n";
NewMyMap= CreatNewSetMap();
cout<<"\nNEWMYSET\n";
cout<<"-------------";
for(map<int,set<int>>::iterator its1 = NewMyMap.begin(); its1 != NewMyMap.end(); ++its1)
cout << endl << its1->first <<" =>";
for(IntSet::iterator sit=its1->second.begin();sit!=its1->second.end();++sit)
cout<<" "<<(*sit);
cout<<"\n\n";
return 0;
bool IsValueNotInSet(int value, IntSet& S)
IntSet::iterator it=find (S.begin(), S.end(), value);
if (it!=S.end())
return false;
return true;
SetMap CreatNewSetMap()
IntSet TSet;
for(IntVec::iterator it = IVec.begin(); it != IVec.end(); ++it)
SetMap::iterator its = mySet.find(*it);
if (its != mySet.end())
TSet.clear();
int key = its->first;
IntSet& itset = its->second;
for(IntVec::iterator itv = myVec.begin(); itv != myVec.end(); ++itv)
if(IsValueNotInSet((*itv), itset))
TSet.insert(*itv);
NewMyMap.insert(make_pair(key,TSet));
return NewMyMap;

Similar Messages

  • How to find first non zero value from the numeric value or string?

    Hiii, Every body
              I have one numeric indicator in which some valuse is coming with the decimal value, lets say 0.00013, now i want to find the first non-zero value from this numeric indicator, then what should i do to do so? i have converted it in the string, but i could not find any method to find first non-zero value from that string or either from the numeric indicator????
          Can you please help me, how to do it? i have attached the vi and write all the description inside.
    Thanks in Advance,
    Nisahnt
    Attachments:
    Find first nonzero.vi ‏20 KB

    Just convert it to an exponential string and take the first character .
    Message Edited by altenbach on 05-10-2006 08:00 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FisrstNonzeroChar.png ‏3 KB
    FindFirstNonzeroCharacter.vi ‏20 KB

  • How to find make most common value?

    Hello,
    I have data like this
    Customer Invoice number payment term
    ABC 10001 K20
    ABC 10002 K40
    ABC 10003 K20
    ZYX 10004 K30
    ZYX 10005 K20
    ZYX 10006 K30
    Now I want to make report which will show most common payment term. I tried with count etc. with no result.
    I want report like this
    ABC K20
    ZYX K30
    Regards,
    Luko

    Hi,
    You can set the GROUP BY clause in the Advanced Tab
    http://gerardnico.com/wiki/dat/obiee/group_by
    Please refer the below links,
    Group By in OBIEE
    Or,
    count(customet by customer,payment term) (or) you can apply those columns in Advanced tab then apply below filter in your report.
    Apply fiter >grather than 1
    Hope this help's
    Thanks,
    Satya

  • How would I find the most common value every nth row in a column

    SCENARIO 1
    I have a column with a series of numbers in c1:c1000 as follows:
    2
    2
    3
    1
    1
    4
    2
    3
    1
    2...
    and I would like to find the most common value for every nth (in this case, second) row.
    SCENARIO 2
    Originally, I created a separate column in J and used this to find a value of 0 or 1 via a filter to label the rows odd or even. I was then going to create two separate columns, one for even rows of data and another for odd rows of data to separate them and perform functions on each column. But I do not know how to copy just the filtered data to one of the new columns to apply the MODE function (or any other for that matter).
    Perhaps my question should be: after applying a filter, how do i copy just the visible filtered data of every nth row to a new column in my spreadsheet while retaining the original column with all rows of data? 
    BACK TO SCENARIO 1
    If I do not need to go through this effort, I would just apply the MODE function (or AVERAGE or SUM) to every nth row in the original data column.

    Since Index and Offset were already taken, I used INDIRECT(ADDRESS()) in my example.
    Here's how I approached it:
    Expressions are as follows...
    Data Subset, Column A, Row 2: =IF(StartingRow :: A, 1, NSelector :: $A)
    Subsequent rows in Column A: =IF(ROW()<COUNT(Input :: $B)/NSelector :: A:$A+2, A2+NSelector :: $A, "")
    Data Subset, Column B, Rows 3
    throuth the last: =IFERROR(INDIRECT(ADDRESS(A+1, 2, ,,"Input")), "")
    Stats, Column A, Row 2: =IFERROR(MODE(Data Subset :: B), "No Mode")
    Stats, Column B, Row 2: =COUNTIF(Data Subset :: B, A)
    Lots of ways to skin this cat.
    Jerry

  • Finding the most common value in an array of enums

    Hello,
    I'm looking for an elegant way of finding the most common value in an array of enums
    My enum being:
    0 - Close
    1 - Open
    2 - Undefined
    For instance, if my array contains:
    Close, Close, Open, Close, Close, Open.
    The most common value would be "Close"
    I have created a very customized VI that allows me to obtain the desired result, but I'm really not proud of doing it this way, simply because I would have to modify it if I were to add a new value to my enum...
    If someone can share some ideas to enlighten me, I would REALLY appreciate it.
    Thanks in advance!
    Jorge
    Solved!
    Go to Solution.

    Here is the variant using the search method. This method will run N-1 times where N is the number of ENUM elements. Yes, it is a bit more complex than the brute force method but it would execute fairly quickly. The sort would probably be the time consuming task.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot
    Attachments:
    ENUM Counter.vi ‏14 KB
    Enum.ctl ‏4 KB

  • For Multi value attributes, how we can view only the most recent value?

    Where we can set what in endeca servers (MDEX, Clover & Studio) to view only the most recent value of a multi assign value attribute on Studio server?

    That's correct, multi-value attributes do not support this in Endeca.
    If you're looking to do it, I would keep writing your updates to the multi-value attribute (to maintain the functionality that depends on this attribute and its multiple values) and also write it to a separate single-value that is constantly being updated, rather than appended to.
    Something like:
    One attribute called MyValueMulti as a multi-assign.
    AND
    One attribute called MyValueLatest as a single-assign.
    Regards,
    Patrick Rafferty
    http://branchbird.com

  • How to check the whole values of a set of map exist in the vector of map?

    Hi Friends!
    I have a set of map; map<int, set<int>>myset;
    and a vector of map; map<int,vector<int>>myvec;
    myset contains;
    1=>11  16  30
    3=>2  11
    6=>2
    7=>9  12  16
    8=>9  13  16
    myvec contains;
    1=>11  15  21
    2=>16
    3=>11  16
    4=>2  13
    5=>11  16  30
    6=>9  5  10
    First, the first value of myset(11  16  30) will be checked with all the values of myvec, if the whole value(11  16  30) available at certain value in the myset, then it gives the key of myvec. So, the output for the first value is 5.
    Next, if you consider the value (2  11) in the myset, there are no matching values that contains whole 2  11 in the particular value in myvec. Therefore, what we do is, delete the last value of the current set, that is 11, and now consider 2 as
    the value and find the matching value from myvec. That is (2  13) and the key is 4.
    Like wise when we find the first possible match, then we print the key of myset immediately, there may be some other possible values available in the values of myset.
    I have written two functions that check the particular whole values of the myset matched with a particular values in myvec.
    bool IsValueInVec(int value, const IntVec& v2)
    IntVec::const_iterator itv=find (v2.begin(), v2.end(), value);
    if (itv!=v2.end())
    return true;
    return false;
    bool AreAllValuesInVec(const IntSet& s1, const IntVec& v2)
    for(set<int>::const_iterator sit=s1.begin();sit!=s1.end();++sit)
    if (!IsValueInVec((*sit), v2))
    return false;
    return true;
    Could anyone help me to solve this?

    You have neither a set of map nor a vector of map.  You have two maps.  Each contains keys of type int.  The mapped values of one are of type set<int>.  The mapped values of the other are of type vector<int>.  If
    you don't understand the types of the objects you are using, you will never be able to use them properly.
    Help you solve what?  Do the two functions you wrote perform as desired?  If not, provide a complete description of how what they do differs from what you want.
    Somewhere in code you have not shown, you need to call AreAllValuesInVec for a particular set and vector.  If this function returns false and if the set contains more than one element, you need to delete the last element of the set and try again. 
    If the set contains only a single element, you need to perform some "failure" processing that you have not described.  When the function returns true, you need to print the key of the map element which contains the vector.  What are you
    having trouble with?

  • WARNING: ADFv: Could not find selected item matching value ...

    Using Windows JDev 11.1; I have an entity object with an attribute which has a LOV configured to supply a select-one-choice render. The LOV query requires that a bind variable be supplied. When creating a new record in the entity via the VO, I can use the ViewImpl to create a new row, retrieve the RowSet which corresponds to the attribute LOV query, set the named where clause parameter, and I'm away. When updating however, I'm getting the following error reported:
    09/12/2009 2:44:04 PM oracle.adfinternal.view.faces.model.binding.FacesCtrlListBinding getInputValue
    WARNING: ADFv: Could not find selected item matching value EMPLOYER of type: java.lang.String in the list-of-values.
    I can't supply the bind variable value before the row is instantiated (and presumably populated with the current value/key) because the View Accessor RowSet is only accessible via the RowImpl. If after the query has executed, I apply the bind variable value, re-execute the RowSet query, I can see that it's populated, and I can create a RowSetIterator to loop through the LOV RowSet and confirm that the key/value is there. I can even setCurrentRow on the RowSet but I still find that the above error appears in the serve log output seemingly after all this code executes.
    So my question is what is the technique for supplying bind variables to attribute LOV View Accessors as part of an underlying EO object query.
    In the run-time, the list items appear unpopulated (current value and list items). If I reload the page, it all comes up fine, which could tend to suggest that a PPR event might fix me up, but I would prefer to know how this should be done.
    Thanks in advance.
    Edited by: robli on Dec 9, 2009 9:01 PM

    Hi,
    Is your issue resolved. I'm facing similar issue. I have created a viewaAccessors in EO, associated these to ViewObject attributes as List of Values.
    I created the table in UI using the ViewObject.
    I see those as selectOneChoice but not values (Empty list).
    If I create new record in the table by CreateInsert. table now shows the ListOfvalues.
    any Idea what am I missing.
    Thanks,
    Satya
    Edited by: stammine on Mar 2, 2010 4:09 PM

  • Creating a view on two ODS using the most actual value of Timestamp

    Hi All,
    I am creating a view on two ODS. I have made an internal join of the field timestamp from both the tables. But the timestamp in bot ODS do not match, which is why there is no data visible in the view.
    There is a requirement that the value of timestamp to be used has to be the most actual value of timestamp from the two ODS.
    I would be grateful if some pointers regarding the same could be provided.
    Thanks and regards,
    Shruti Kulkarni

    Hi Shruti,
    ODS should not be linked on Timestamp basis, there must be some other alternatives like document number, date etc etc...
    In other case if its possible to include addtional key figure in to ODS then
    create a dummy key figure , in the aggregation tab page Select Exception aggregate as "Last Value" and in the "agg.ref char" Select time stamp as info object. This setting will make sure that in the ODS you have only last updated data.
    Hope that helps.
    Regards
    Mr Kapadia
    Assigning points is the way to say thanks in SDN.

  • How do I pass a null value to the reportDocument?

    I'm using CR 2008 and VS 2005. 
    I am using a stored procedure as the datasource for one of my report, which we run using the C# API.   The stored procedure is expecting a NULL in certain cases and I find I cannot pass a NULL with my current code:
    // Here I get the parameter
    // If we are dealing with an empty string or a NULL value, let's give it
                            // a value of a space so that Crystal's DLLs don't choke.
                            if ((value.Length == 0) || (value == "NULL"))
                                value = " ";
                            arrParams.Add(value);
    Object strParam = arrParams<i>;
    this.reportDocument1.SetParameterValue(num, strParam);
    The stored procedure parameter type is INT so in the report it shows up as NUMBER.
    How do I get a NULL value to the stored procedure?
    Thanks.

    See if this does the trick:
    Dim crParameterDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue()
    crParameterDiscreteValue.Value = Nothing
    C# would look something like;
    CrystalDecisions.Shared.ParameterDiscreteValue crParameterDiscreteValue;
    crParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
    crParameterDiscreteValue.Value = null;
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup

  • Could not find selected item matching value "null" in CoreSelectOneRadio

    Hello,
    I get the following error with my selectOneChoice components:
    WARNING Could not find selected item matching value "null" in CoreSelectOneRadio[UIXEditableFacesBeanImpl, id=dyna_2709976_11]
    It seem that the component looks for a selectItem object qith its value set to null, so I tried to add one with a null value to no avail. The error don't cause any problem on the rendered page but it might spam the log when many users will be connected. Anyone every got this error and found a fix to stop it from appearing?
    Regards,
    Simon Lessard

    you said you're using selectOneChoice but the error says radio. Is the information correct?

  • Could not find selected item matching value "New" warning message in ADF

    Hi,
    I have a selectOneChoice1 for a field which has the following fixed values in it. And while creating it, I selected the 'SelctionRequired' option so that this field will always have a value.
    New
    Pending
    Completed.
    While navigating to this page, I am trying to set the value to 'New' (Retrieved from the DB) in the backing bean. But when the page is rendered, the above field is empty with the above options in the list and jdev has the follwing error message in its log.
    WARNING: Could not find selected item matching value "New" in CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=selectOneChoice1]
    Can any one help me with this issue?
    Thanks,
    Priya

    The value of a list binding is the zero-based integer position in the list that is selected, not the actual underlying value.
    The simplest way to set the value of an attribute is to use an attribute binding (which can be bound to the same attribute as the list binding). When you set the value of an attribute binding, it sets the value as you supply it. Otherwise, you'd need to set the list binding's value to the numerical "slot" number of the one you want to change the value to.

  • How to find if COLUMN DEFAULT VALUE is stored as metadata?

    Hello,
    I'm using Oracle 11g enhanced ADD COLUMN Functionality. Adding new columns with DEFAULT values and NOT NULL constraint no longer requires the default value to be stored in all existing records.
    Sometimes we change DB columns from NOT NULL with DEFAULT to NULL with DEFAULT. This operation "materialize" column default.
    Is there an easy way (Dictionary view) how to find, that COLUMN default value is stored as metadata or is "materialized" ?
    Thanks. Filip
    Oracle RDBMS version : Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

    Thanks for your suggestion, but it is not what i'm looking for :-(
    I don't need to find the default value, i need to know how is default value stored. It could be stored in 2 ways.
    1. "materialized" - prior to 11G (value is physicaly stored for every column)
    2. "as a metadata" - new 11G functionality (default is not physicaly stored and if you query the column DB transalte NULL value to defaut value)
    Now I would like to now if my column is type 1) or 2). How can I do it?
    Thank you.Filip

  • How should I understand the parameters/argument values in the {} and [] right after a function?

    Hi,
    How should I understand the parameters/argument values in the {} and [] right after a function?
    For instance the {[Name="control"]}[Content] part in the
    control=Excel.CurrentWorkbook(){[Name="control"]}[Content]
    and also the [Control]{0} part in the periodctrl=control[Control]{0}.
    Thanks.
    Regards,

    The "[]" operator in M is like the "." operator in C-like languages, if that helps. It takes an aggregate value with named components and it selects one of those components. In the case of the record "Foo", "Foo[Bar]"
    returns the field named Bar. In the case of the table "Baz", "Baz[Quux]" returns the column named Quux.
    Similarly, the "{}" operator in M does subscripting of lists -- like the "[]" operator in C-like languages. If "Foo" is a list, then "Foo{0}" returns the first element of the list, "Foo{1}" returns the second
    element of the list, and so on.
    In the case of tables, it's also possible to use "{}" with a record argument, in which case it will return the row which matches the record criteria -- provided there is exactly one. So if "Foo" is a table, then "Foo{[Bar = 1]}"
    will return the row for which the Bar column has a value of 1.
    Many of the data access functions in Power Query return what we call "navigation tables". Sql.Database, for instance, returns a table with columns named Name, Schema, Object, Kind and Data. Each table in the database has a single entry in this
    navigation table. When we index into the table with "table{[Schema="dbo", Object="table"]}", we're selecting the single row that matches those criteria. This gives us a record. We then want to pick the "Data" field of
    that record, which contains the actual table data. That's why there's typically a "[Data]" at the end of expressions which fetch data from the SQL table.

  • HT4993 how to find my year of birth on the iphone4

    how to find my year of birth on the iphone4

    It sounds as if it wants the answer to your security question "what is the year of your birth".
    Apple has been using these security questions for a few months now. Presumably it is to avoid theft from people guessing other people's Apple IDs and passwords. No one knows why or when anyone is asked for the answers, and like any good security system it is designed to be unpredictable.
    Whatever you answered for that question, only you can know, that's the idea behind the security questions. You could have answered 1492, it really doesn't matter, as long as your answer matches what you originally supplied.
    If you are being locked out because your answer is not what it is expecting, your only recourse is to contact iTunes Support and ask them to reset your password. You will have to answer some questions to confirm you are who you say you are, and then they will send you an email with instructions to reset your password and create new answers to more security questions.
    Contact iTunes Support here: http://www.apple.com/emea/support/itunes/contact.html

Maybe you are looking for

  • I miss the old Homesite

    I'm in a bit of a delima. I have used an old version of Homesite for some time now. It was the version that would allow the three views; edit, preview, and the editable WUSIWYG screen. As I'm sure all of you know, this version will no longer work wit

  • My iPod does not turn on and it is not recognized by my laptop in iTunes... What can I do?

    My iPod does not turn on and it is not recognized by my laptop in iTunes... What can I do? Model iPod 2 Touch, 8G, It stoped working less than a month after it was purchased but I never sent it back for repairs or warranty to Apple.. Is there still a

  • Problem in saving variant

    Hi All, I copied standard report to custom report. Added one extra field on selection screen of copied  custom report. When i save the variant, data is saved on selection screen. But when i select the variant, values are populated for other fields ex

  • Photo captions on iPad

    When I synch from iPhoto on my iMac to the photo app on my iPad, I lose the titles/captions. Is there any way of keeping these titles so they show on my iPad?

  • My front and back camera won't work, and my flash will not either.

    I took some picture in the rain, my iPod 5th gen wasn't affected, then my iPod was dropped in a parking lot and found later. Other than that, nothing has really happened to it, but both the front and back camera do not work. When I open up a camera,