Click here to Skip to main content
16,012,061 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: how to convert an array of records into a hierarchical structure Pin
getroshan6-Sep-10 21:47
getroshan6-Sep-10 21:47 
AnswerRe: how to convert an array of records into a hierarchical structure Pin
Andrew Rissing11-Oct-10 4:12
Andrew Rissing11-Oct-10 4:12 
GeneralAutomatic Assignment Pin
alkowarizmi27-Jul-10 14:38
alkowarizmi27-Jul-10 14:38 
AnswerRe: Automatic Assignment Pin
Luc Pattyn27-Jul-10 14:58
sitebuilderLuc Pattyn27-Jul-10 14:58 
GeneralRe: Automatic Assignment Pin
alkowarizmi28-Jul-10 3:47
alkowarizmi28-Jul-10 3:47 
GeneralRe: Automatic Assignment Pin
Luc Pattyn28-Jul-10 4:04
sitebuilderLuc Pattyn28-Jul-10 4:04 
GeneralRe: Automatic Assignment Pin
Yusuf28-Jul-10 4:07
Yusuf28-Jul-10 4:07 
GeneralRe: Automatic Assignment Pin
getroshan7-Sep-10 0:44
getroshan7-Sep-10 0:44 
you can get a bit idea with this code. Sorry I have not commented the code. was a quick example for you to get started if required.

<br />
  public class Paper<br />
        {<br />
            private string _name;<br />
<br />
            public string Name<br />
            {<br />
                get { return _name; }<br />
                set { _name = value; }<br />
            }<br />
            private List<string> keywords;<br />
<br />
            public List<string> Keywords<br />
            {<br />
                get { return keywords; }<br />
                set { keywords = value; }<br />
            }<br />
<br />
            private Reviewer _paperreviewer;<br />
<br />
            public Reviewer PaperReviewer<br />
            {<br />
                get { return _paperreviewer; }<br />
                set { _paperreviewer = value; }<br />
            }<br />
        }<br />
<br />
     public class Reviewer<br />
        {<br />
            private string _name;<br />
<br />
            public string Name<br />
            {<br />
                get { return _name; }<br />
                set { _name = value; }<br />
            }<br />
            private List<string> keywords;<br />
<br />
            public List<string> Keywords<br />
            {<br />
                get { return keywords; }<br />
                set { keywords = value; }<br />
            }<br />
<br />
            private int reviewCount;<br />
<br />
            public int ReviewCount<br />
            {<br />
                get { return reviewCount; }<br />
                set { reviewCount = value; }<br />
            }<br />
        }<br />
<br />
<br />
  class PaperList<br />
<br />
  {<br />
        private List<Reviewer> _reviewers = new List<Reviewer>();<br />
        private List<Paper> _papers = new List<Paper>();<br />
        private IReviewStrategy _reviewstrategy;<br />
<br />
        public PaperList(List<Paper> papers, List<Reviewer> reviewers)<br />
        {<br />
            _papers = papers;<br />
            _reviewers = reviewers;<br />
        }<br />
<br />
        public void SetReviewStrategy(IReviewStrategy reviewstrategy)<br />
        {<br />
            this._reviewstrategy = reviewstrategy;<br />
        }<br />
<br />
        public void Review()<br />
        {<br />
            _papers=_reviewstrategy.FindReviewer(_papers, _reviewers);<br />
            foreach (Paper p in _papers)<br />
            {<br />
                string reviewername=string.Empty;<br />
                if (p.PaperReviewer != null)<br />
                    reviewername = p.PaperReviewer.Name;<br />
                else<br />
                    reviewername = "None";<br />
                Console.WriteLine(p.Name + " is reviewed by " + reviewername);<br />
            }<br />
        }<br />
<br />
  }<br />
<br />
  public interface IReviewStrategy<br />
        {<br />
             List<Paper> FindReviewer(List<Paper> papers, List<Reviewer> reviewers); <br />
        }<br />
<br />
        public class SimpleReviewStrategy:IReviewStrategy<br />
        {<br />
            public List<Paper> FindReviewer(List<Paper> papers, List<Reviewer> reviewers)<br />
            {<br />
                int KeyWordMatch=0;<br />
                Reviewer bestReviewer = null;<br />
                int bestKeyWordCount=0;<br />
                foreach (Paper p in papers)<br />
                {<br />
                    bestReviewer = null;<br />
                    bestKeyWordCount=0;<br />
                    foreach (Reviewer r in reviewers)<br />
                    {<br />
                        KeyWordMatch = CountKeyWordOccurences(p.Keywords, r.Keywords);<br />
                        if (KeyWordMatch > 0 && KeyWordMatch >= bestKeyWordCount)<br />
                        {<br />
                            if (KeyWordMatch > bestKeyWordCount)<br />
                            {<br />
                                bestKeyWordCount = KeyWordMatch;<br />
                                bestReviewer = r;<br />
                            }<br />
                            else<br />
                            {<br />
                                if (r.ReviewCount < bestReviewer.ReviewCount)<br />
                                {<br />
                                    bestKeyWordCount = KeyWordMatch;<br />
                                    bestReviewer = r;<br />
                                }<br />
                            }<br />
                        }<br />
<br />
                    }<br />
                    if (bestReviewer != null)<br />
                        p.PaperReviewer = bestReviewer;<br />
                }<br />
                return papers;<br />
            }<br />
            private int CountKeyWordOccurences(List<string> list1, List<string> list2)<br />
            {<br />
                int counter = 0;<br />
                foreach (string l1 in list1)<br />
                {<br />
                    if (list2.Contains(l1))<br />
                        counter++;<br />
                }<br />
                return counter;<br />
            }<br />
        }<br />
<br />
 private void button1_Click(object sender, EventArgs e)<br />
        {<br />
<br />
            List<string> keywordset1=new List<string>();<br />
            keywordset1.Add("music");<br />
            List<string> keywordset2=new List<string>();<br />
            keywordset2.Add("music");<br />
            keywordset2.Add("science");<br />
            List<string> keywordset3=new List<string>();<br />
            keywordset3.Add("animal");<br />
             keywordset3.Add("bird");<br />
            keywordset3.Add("trees");<br />
           List<string> keywordset4=new List<string>();<br />
            keywordset4.Add("men");<br />
            keywordset4.Add("women");<br />
<br />
            List<string> keywordset5=new List<string>();<br />
            keywordset5.Add("men");<br />
            keywordset5.Add("animal");<br />
            keywordset5.Add("music");<br />
            keywordset5.Add("women");<br />
<br />
           List<string> keywordset6=new List<string>();<br />
            keywordset6.Add("love");<br />
             keywordset6.Add("music");<br />
<br />
             List<string> keywordset7 = new List<string>();<br />
             keywordset7.Add("sex");<br />
           <br />
<br />
            List<Reviewer> reviewers = new List<Reviewer>();<br />
            reviewers.Add(new Reviewer { Name = "Roshan", Keywords = keywordset2, ReviewCount = 0 });<br />
            reviewers.Add(new Reviewer { Name = "Alice", Keywords = keywordset4, ReviewCount = 0 });<br />
<br />
            List<Paper> papers = new List<Paper>();<br />
            papers.Add(new Paper { Name = "P1", Keywords = keywordset5, PaperReviewer = null });<br />
            papers.Add(new Paper { Name = "P2", Keywords = keywordset6, PaperReviewer = null });<br />
            papers.Add(new Paper { Name = "P21", Keywords = keywordset7, PaperReviewer = null });<br />
<br />
            PaperList simple = new PaperList(papers, reviewers);<br />
            simple.SetReviewStrategy(new SimpleReviewStrategy());<br />
            simple.Review();<br />
       <br />
           <br />
        }<br />

QuestionWANTED: Programmer looking for an algorithmic challenge PinPopular
Xpnctoc23-Jul-10 5:58
Xpnctoc23-Jul-10 5:58 
AnswerRe: WANTED: Programmer looking for an algorithmic challenge Pin
PIEBALDconsult23-Jul-10 17:01
mvePIEBALDconsult23-Jul-10 17:01 
AnswerRe: WANTED: Programmer looking for an algorithmic challenge Pin
ProtoBytes24-Jul-10 11:57
ProtoBytes24-Jul-10 11:57 
GeneralRe: WANTED: Programmer looking for an algorithmic challenge Pin
Xpnctoc24-Jul-10 12:09
Xpnctoc24-Jul-10 12:09 
AnswerRe: WANTED: Programmer looking for an algorithmic challenge Pin
ProtoBytes24-Jul-10 12:56
ProtoBytes24-Jul-10 12:56 
GeneralRe: WANTED: Programmer looking for an algorithmic challenge Pin
Xpnctoc25-Jul-10 8:29
Xpnctoc25-Jul-10 8:29 
GeneralRe: WANTED: Programmer looking for an algorithmic challenge Pin
ProtoBytes25-Jul-10 8:59
ProtoBytes25-Jul-10 8:59 
GeneralRe: WANTED: Programmer looking for an algorithmic challenge Pin
Xpnctoc25-Jul-10 10:45
Xpnctoc25-Jul-10 10:45 
AnswerRe: WANTED: Programmer looking for an algorithmic challenge [modified] Pin
Luc Pattyn25-Jul-10 12:12
sitebuilderLuc Pattyn25-Jul-10 12:12 
AnswerRe: WANTED: Programmer looking for an algorithmic challenge Pin
Member 419459325-Jul-10 12:52
Member 419459325-Jul-10 12:52 
QuestionGet the angle in radians of a shape made up with 2D points? Pin
venomation20-Jul-10 9:01
venomation20-Jul-10 9:01 
AnswerRe: Get the angle in radians of a shape made up with 2D points? Pin
Alan Balkany21-Jul-10 3:53
Alan Balkany21-Jul-10 3:53 
GeneralRe: Get the angle in radians of a shape made up with 2D points? Pin
venomation21-Jul-10 7:30
venomation21-Jul-10 7:30 
Questiondetect recursion during compilation Pin
invader8215-Jul-10 22:46
invader8215-Jul-10 22:46 
AnswerRe: detect recursion during compilation Pin
Alan Balkany16-Jul-10 4:04
Alan Balkany16-Jul-10 4:04 
AnswerRe: detect recursion during compilation Pin
Peter_in_278016-Jul-10 14:41
professionalPeter_in_278016-Jul-10 14:41 
AnswerRe: detect recursion during compilation Pin
T M Gray23-Jul-10 6:27
T M Gray23-Jul-10 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.