THE JR PROGRAMMING LANGUAGE phần 8

khoản. Yêu cầu này ngăn cản các nỗ lực tuyên truyền của các viện dẫn khả năng và hoạt động trường hợp ngoại lệ không được liệt kê trong các điều khoản ném tương trường hợp ngoại lệ được liệt kê trong mệnh đề throws của một lệnh hoạt động phải phù hợp với | 254 The Traveling Salesman Problem return true iff city already on this path private static boolean visited int path int city body same as in previous section private void update int path int length p mutex get lock for shared variables if length shortest shortest length path V mutex release lock If there are more than a small number of cities . more than ten this program generates a huge number of partial tours. In fact the size of the bag could become so large that the program will run out of memory. A better approach is to put some fixed number of tasks in the bag to start say partial tours of length three. Then on each iteration a worker process extracts one partial tour and uses the sequential algorithm of the previous section to examine all paths starting with that partial tour. In addition to decreasing the amount of storage required for the bag this approach also increases the amount of computation a worker does every time it accesses the bag. Manager and Workers The program in the previous section employs shared variables. However variables cannot be shared across virtual machines. Instead each gets its own copy. Here we present a distributed program that does not use shared variables. To do so we now represent each worker within a separate class TSPWorker. However the bag of tasks and shortest path are now maintained within the compute class which contains a manager process. The workers and manager use asynchronous message passing RPC and rendezvous to communicate with each other. The main class and the results class are identical to those in the previous solution. See the previous sections for their code. As in the previous section the worker process repeatedly gets a partial tour from the bag and extends it with all cities that have not yet been visited. A worker process simply receives a new task from the bag even though bag is declared in a different class which could even be located on a different virtual machine . Manager

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
10    68    1    14-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.