org/objectweb/proactive/core/group/topology/TorusCube.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.group.topology;
00032 
00033 import org.objectweb.proactive.core.group.Group;
00034 import org.objectweb.proactive.core.group.ProxyForGroup;
00035 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
00036 
00037 
00043 public class TorusCube extends Torus { // implements Topology3D {
00044 
00046     protected int depth; //  => Y => number of Toruss
00047 
00056     public TorusCube(Group g, int height, int width, int depth)
00057         throws ConstructionOfReifiedObjectFailedException {
00058         super(g, height * width * depth);
00059         this.height = height;
00060         this.width = width;
00061         this.depth = depth;
00062     }
00063 
00068     public int getWidth() {
00069         return this.width;
00070     }
00071 
00076     public int getHeight() {
00077         return this.height;
00078     }
00079 
00084     public int getDepth() {
00085         return this.depth;
00086     }
00087 
00093     private int getX(int position) {
00094         return (position % (this.width * this.height)) % this.width;
00095     }
00096 
00102     private int getY(int position) {
00103         return (position % (this.width * this.height)) % this.height;
00104     }
00105 
00111     private int getZ(int position) {
00112         return position / (this.width * this.height);
00113     }
00114 
00120     public Object left(Object o) {
00121         int positionX = this.getX(this.indexOf(o));
00122         if (positionX != 0) {
00123             return this.get(positionX - 1);
00124         } else {
00125             return null;
00126         }
00127     }
00128 
00134     public Object right(Object o) {
00135         int positionX = this.getX(this.indexOf(o));
00136         if (positionX != this.getWidth()) {
00137             return this.get(positionX + 1);
00138         } else {
00139             return null;
00140         }
00141     }
00142 
00148     public Object up(Object o) {
00149         int positionY = this.getY(this.indexOf(o));
00150         if (positionY != 0) {
00151             return this.get(positionY - this.getWidth());
00152         } else {
00153             return null;
00154         }
00155     }
00156 
00162     public Object down(Object o) {
00163         int positionY = this.getY(this.indexOf(o));
00164         if (positionY != this.getHeight()) {
00165             return this.get(positionY + this.getWidth());
00166         } else {
00167             return null;
00168         }
00169     }
00170 
00176     public Object ahead(Object o) {
00177         int positionZ = this.getZ(this.indexOf(o));
00178         if (positionZ != 0) {
00179             return this.get(positionZ - (this.getWidth() * this.getHeight()));
00180         } else {
00181             return null;
00182         }
00183     }
00184 
00190     public Object behind(Object o) {
00191         int positionZ = this.getZ(this.indexOf(o));
00192         if (positionZ != this.getDepth()) {
00193             return this.get(positionZ + (this.getWidth() * this.getHeight()));
00194         } else {
00195             return null;
00196         }
00197     }
00198 
00204     public Ring RingX(Object o) {
00205         int position = this.indexOf(o);
00206         int posY = this.getY(position);
00207         int posZ = this.getZ(position);
00208 
00209         ProxyForGroup tmp = null;
00210         try {
00211             tmp = new ProxyForGroup(this.getTypeName());
00212         } catch (ConstructionOfReifiedObjectFailedException e) {
00213             e.printStackTrace();
00214         }
00215 
00216         int begining = (posZ * (this.getHeight() * this.getWidth())) +
00217             (posY * this.getWidth());
00218         for (int i = begining; i < (begining + this.getWidth()); i++) {
00219             tmp.add(this.get(i));
00220         }
00221         Ring result = null;
00222         try {
00223             result = new Ring((Group) tmp, this.getWidth());
00224         } catch (ConstructionOfReifiedObjectFailedException e) {
00225             e.printStackTrace();
00226         }
00227         return result;
00228     }
00229 
00235     public Ring RingY(Object o) {
00236         int position = this.indexOf(o);
00237         int posX = this.getX(position);
00238         int posZ = this.getZ(position);
00239 
00240         ProxyForGroup tmp = null;
00241         try {
00242             tmp = new ProxyForGroup(this.getTypeName());
00243         } catch (ConstructionOfReifiedObjectFailedException e) {
00244             e.printStackTrace();
00245         }
00246 
00247         int begining = (posZ * (this.getHeight() * this.getWidth())) + posX;
00248         for (int i = 0; i < this.getHeight(); i++) {
00249             tmp.add(this.get(begining + (i * this.getWidth())));
00250         }
00251         Ring result = null;
00252         try {
00253             result = new Ring((Group) tmp, this.getWidth());
00254         } catch (ConstructionOfReifiedObjectFailedException e) {
00255             e.printStackTrace();
00256         }
00257         return result;
00258     }
00259 
00265     public Ring RingZ(Object o) {
00266         int position = this.indexOf(o);
00267         int posY = this.getY(position);
00268         int posZ = this.getZ(position);
00269 
00270         ProxyForGroup tmp = null;
00271         try {
00272             tmp = new ProxyForGroup(this.getTypeName());
00273         } catch (ConstructionOfReifiedObjectFailedException e) {
00274             e.printStackTrace();
00275         }
00276 
00277         int begining = (posY * this.getWidth()) + posY;
00278         for (int i = 0; i < this.getDepth(); i++) {
00279             tmp.add(this.get(begining +
00280                     (i * (this.getWidth() * this.getHeight()))));
00281         }
00282         Ring result = null;
00283         try {
00284             result = new Ring((Group) tmp, this.getWidth());
00285         } catch (ConstructionOfReifiedObjectFailedException e) {
00286             e.printStackTrace();
00287         }
00288         return result;
00289     }
00290 
00296     public Torus TorusX(Object o) {
00297         ProxyForGroup tmp = null;
00298         try {
00299             tmp = new ProxyForGroup(this.getTypeName());
00300         } catch (ConstructionOfReifiedObjectFailedException e) {
00301             e.printStackTrace();
00302         }
00303 
00304         int begining = this.getX(this.indexOf(o));
00305         ;
00306         for (int i = 0; i < this.getHeight(); i++) {
00307             for (int j = 0; j < this.getDepth(); j++) {
00308                 tmp.add(this.get((begining + (i * this.getWidth())) +
00309                         (j * (this.getWidth() * this.getHeight()))));
00310             }
00311         }
00312         Torus result = null;
00313         try {
00314             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00315         } catch (ConstructionOfReifiedObjectFailedException e) {
00316             e.printStackTrace();
00317         }
00318         return result;
00319     }
00320 
00326     public Torus TorusY(Object o) {
00327         ProxyForGroup tmp = null;
00328         try {
00329             tmp = new ProxyForGroup(this.getTypeName());
00330         } catch (ConstructionOfReifiedObjectFailedException e) {
00331             e.printStackTrace();
00332         }
00333 
00334         int begining = this.getY(this.indexOf(o)) * this.getWidth();
00335         for (int i = 0; i < this.getWidth(); i++) {
00336             for (int j = 0; j < this.getDepth(); j++) {
00337                 tmp.add(this.get((begining + (i * this.getWidth())) +
00338                         (j * (this.getWidth() * this.getHeight()))));
00339             }
00340         }
00341         Torus result = null;
00342         try {
00343             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00344         } catch (ConstructionOfReifiedObjectFailedException e) {
00345             e.printStackTrace();
00346         }
00347         return result;
00348     }
00349 
00355     public Torus TorusZ(Object o) {
00356         ProxyForGroup tmp = null;
00357         try {
00358             tmp = new ProxyForGroup(this.getTypeName());
00359         } catch (ConstructionOfReifiedObjectFailedException e) {
00360             e.printStackTrace();
00361         }
00362 
00363         int begining = this.getZ(this.indexOf(o)) * (this.getWidth() * this.getHeight());
00364         for (int i = 0; i < (this.getWidth() * this.getHeight()); i++) {
00365             tmp.add(this.get(begining + i));
00366         }
00367         Torus result = null;
00368         try {
00369             result = new Torus((Group) tmp, this.getWidth(), this.getDepth());
00370         } catch (ConstructionOfReifiedObjectFailedException e) {
00371             e.printStackTrace();
00372         }
00373         return result;
00374     }
00375 }

Generated on Mon Jan 22 15:16:08 2007 for ProActive by  doxygen 1.5.1