Ejemplo n.º 1
0
 def simple(self):
     # simple test without cleanup:
     assert len(self._polygon) > 3 
     gallery = ArtGallery(self._polygon.pop(self.main_index))
     for point in self._polygon:
         gallery.include(point)
             
     self.preview_control.show(gallery, title = "Without cleanup")
Ejemplo n.º 2
0
class TestProcess(threading.Thread):
    '''
    Generate a mono and mult thread test for Art Gallery Previewer
    '''
    STARTING = 1
    RUNNING = 2
    STOPPING = 3
    
    num_threads = 0
    lock = threading.Lock()
    _big_delay = 0.25
    
    def __init__(self, points, index_main_point, delay):
        with TestProcess.lock:
            self.id = TestProcess.num_threads
            TestProcess.num_threads += 1
            self._polygon = points[:]
            ArtGalleryPainter.set_polygon(self._polygon)
            self.gallery = ArtGallery(self._polygon.pop(index_main_point))
        self.delay = delay
        self.big_delay = TestProcess._big_delay \
                         if delay < TestProcess._big_delay \
                         else delay
        self.state = TestProcess.STARTING
        threading.Thread.__init__(self)
        self.counter = 0
        

    def start(self):
        threading.Thread.start(self)

    def stop(self):
        self.state = TestProcess.STOPPING
        
    def must_exit(self):
        self.counter += 1
        threading.Event().wait(self.delay)
        return self.state != TestProcess.RUNNING

    def must_exit_delay(self, delay):
        self.counter += 1
        threading.Event().wait(delay)
        return self.state != TestProcess.RUNNING

    def run(self):
        self.state = TestProcess.RUNNING
        while True:
            size = len(self._polygon)
            if size == 0 or self.must_exit(): break
            index = random.randint(0, size - 1)
            point = self._polygon.pop(index)
            self.gallery.include(point)
        # keep running until receive a stop sign
        while self.state == TestProcess.RUNNING:
            pass
Ejemplo n.º 3
0
 def __init__(self, points, index_main_point, delay):
     with TestProcess.lock:
         self.id = TestProcess.num_threads
         TestProcess.num_threads += 1
         self._polygon = points[:]
         ArtGalleryPainter.set_polygon(self._polygon)
         self.gallery = ArtGallery(self._polygon.pop(index_main_point))
     self.delay = delay
     self.big_delay = TestProcess._big_delay \
                      if delay < TestProcess._big_delay \
                      else delay
     self.state = TestProcess.STARTING
     threading.Thread.__init__(self)
     self.counter = 0
Ejemplo n.º 4
0
        area = 0.0
        i0 = size -1
        i1 = 0
        while i1 < size:
            area += self._polygon[i0].x * self._polygon[i1].y - \
                    self._polygon[i0].y * self._polygon[i1].x
            i0 = i1 
            i1 += 1
        return (area / 2)

# Testing the class
if __name__ == "__main__":

    from art_gallery import ArtGallery

    points = ArtGallery.load("inputs/test_0.poly")

    points.sort()
    triangulation = Triangulation(points)
    triangulation.process()
    from coloring import Coloring
    color = Coloring(points, triangulation)
    color.process()
    i = 0
    for p in triangulation._polygon:
        i += 1
        print "Point %d => %s"  % (i, p)
    i = 0
    for t in triangulation.get_triangles():
        i += 1
        print "Triangle %d => (%s,%s)[%s] (%s,%s)[%s] (%s,%s)[%s]" \
Ejemplo n.º 5
0
# Do not show log
logging.config.dictConfig({'version': 1, 'loggers': {}})

# VoronoiDiagram.start()
global_settings.ENVIRONMENT2D_SHAPE = (500, 500)


# Read the file name from command line
try:
    file_name = argv[1]
except IndexError:
    print "No input file"
    exit()

polygon = ArtGallery.load(file_name)
n_nodes = len(polygon)

# generates the network with 10 hosts
net_gen = NetworkGenerator(n_count=n_nodes-1, n_min=1, n_max=n_nodes)
net = net_gen.generate_random_network()

ArtGalleryPainter.set_polygon(polygon)

label = "Distributed Solution for Art Gallery Problem"

max_x = 0
max_y = 0
for p in polygon:
    
    # Correction on polygon draw on window
Ejemplo n.º 6
0
 def set_cenario(self, file_name):
     self.delay = 0.25
     self._polygon = ArtGallery.load(file_name)
     self.preview_control = PreviewControl(ArtGalleryPainter)
     self.fps = 0