/[projects]/queensgui/src/containerminimalvector.cpp
ViewVC logotype

Annotation of /queensgui/src/containerminimalvector.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (hide annotations) (download)
Wed Jul 25 19:29:51 2007 UTC (16 years, 10 months ago) by torben
File size: 3174 byte(s)
Optimized the addsolution() implemntation, to avoid all the temporary rotate() and mirror() calls. ContainerMinimalVector is now the fastest container.

1 torben 13 /***************************************************************************
2     * Copyright (C) 2005 by Torben Nielsen *
3     * torben@t-hoerup.dk *
4     * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the *
17     * Free Software Foundation, Inc., *
18     * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19     ***************************************************************************/
20     #include "containerminimalvector.h"
21    
22     #include <memory>
23     #include "solution.h"
24    
25     ContainerMinimalVector::ContainerMinimalVector(GUIUpdate* update): SolutionContainer(update)
26     {
27     m_total = 0;
28     }
29    
30    
31     ContainerMinimalVector::~ContainerMinimalVector()
32     {
33     }
34    
35    
36     int ContainerMinimalVector::getUniqueRemoved()
37     {
38     return m_total - m_solutions.size();
39     }
40    
41     int ContainerMinimalVector::numSolutions()
42     {
43     return m_solutions.size();
44     }
45    
46     int ContainerMinimalVector::totalSolutions()
47     {
48     return m_total;
49     }
50    
51     Solution* ContainerMinimalVector::solution(int index)
52     {
53     return m_solutions[index].get();
54     }
55    
56     void ContainerMinimalVector::addSolution(Solution* sol)
57     {
58 torben 14 std::auto_ptr<Solution> norm1( sol->copy() );
59     std::auto_ptr<Solution> norm2( sol->copy() );
60     std::auto_ptr<Solution> norm3( sol->copy() );
61    
62     std::auto_ptr<Solution> mirror1( sol->copy() );
63     std::auto_ptr<Solution> mirror2( sol->copy() );
64     std::auto_ptr<Solution> mirror3( sol->copy() );
65     std::auto_ptr<Solution> mirror4( sol->copy() );
66 torben 13 bool found = false;
67    
68 torben 14 norm1->rotate90();
69     norm2->rotate90();
70     norm2->rotate90();
71     norm3->rotate90();
72     norm3->rotate90();
73     norm3->rotate90();
74    
75     mirror1->mirror();
76     mirror2->mirror();
77     mirror2->rotate90();
78     mirror3->mirror();
79     mirror3->rotate90();
80     mirror3->rotate90();
81     mirror4->mirror();
82     mirror4->rotate90();
83     mirror4->rotate90();
84     mirror4->rotate90();
85    
86     for (VIt it = m_solutions.begin(); it != m_solutions.end() && found == false; it++)
87 torben 13 {
88 torben 14 if ( *norm1 == *(*it) || *norm2 == *(*it) || *norm3 == *(*it) ||
89     *mirror1 == *(*it) || *mirror2 == *(*it) || *mirror3 == *(*it) || *mirror4 == *(*it))
90 torben 13 {
91     found = true;
92     break;
93     }
94     }
95     if (found == false)
96     {
97     m_solutions.push_back( boost::shared_ptr<Solution>(sol) );
98     m_total++;
99     }
100     }
101    
102     void ContainerMinimalVector::uniqueSolutions()
103     {
104     // Do nothing
105     }

  ViewVC Help
Powered by ViewVC 1.1.20