示例#1
0
void test_for_AE()
{
    MatrixXd    datasets(4,2);
    datasets<<0,0,1,0,0,1,1,1;
    
    AutoEncoder ae(2);
    ae.add_layer(5);
    ae.add_layer(3);
    ae.add_layer(5);
    
    ae.train(datasets, 10000, 0.5, 0.1);
    cout<<ae.infer(datasets.row(0))<<endl;
    cout<<ae.infer(datasets.row(1))<<endl;
    cout<<ae.infer(datasets.row(2))<<endl;
    cout<<ae.infer(datasets.row(3))<<endl;
    
    cout<<ae.infer_represent(datasets.row(0))<<endl;
    cout<<ae.infer_represent(datasets.row(1))<<endl;
    cout<<ae.infer_represent(datasets.row(2))<<endl;
    cout<<ae.infer_represent(datasets.row(3))<<endl;
}
示例#2
0
NS_IMETHODIMP
ImportLoader::OnDataAvailable(nsIRequest* aRequest,
                              nsISupports* aContext,
                              nsIInputStream* aStream,
                              uint64_t aOffset,
                              uint32_t aCount)
{
  MOZ_ASSERT(mParserStreamListener);

  AutoError ae(this);
  nsresult rv;
  nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mParserStreamListener->OnDataAvailable(channel, aContext,
                                              aStream, aOffset,
                                              aCount);
  NS_ENSURE_SUCCESS(rv, rv);
  ae.Pass();
  return rv;
}
示例#3
0
  bool
  operator== (const Navigation& x, const Navigation& y)
  {
    {
      ::xsd::cxx::tree::comparison_map< char >& cm (
        ::xsd::cxx::tree::comparison_map_instance< 0, char > ());

      Navigation::EventSequence a (x.event ()), b (y.event ());

      if (a.size () != b.size ())
        return false;

      for (Navigation::EventConstIterator
           ai (a.begin ()), bi (b.begin ()), ae (a.end ()), be (b.end ());
           ai != ae; ++ai, ++bi)
      {
        if (!cm.compare (*ai, *bi))
          return false;
      }
    }

    return true;
  }
示例#4
0
void FExtrudeMod::ModifyObject(
		TimeValue t, ModContext &mc, ObjectState *os, INode *node)
	{
	if (os->obj->IsSubClassOf(triObjectClassID)) {
		TriObject *tobj = (TriObject*)os->obj;
		Mesh &mesh = tobj->GetMesh();
		Interval iv = FOREVER;
		float a, s;
		Point3 pt, center;
		int c;
		
		pblock->GetValue(PB_AMOUNT,t,a,iv);
		pblock->GetValue(PB_SCALE,t,s,iv);
		pblock->GetValue(PB_CENTER,t,c,iv);
		base->GetValue(t,&pt,iv,CTRL_ABSOLUTE);		

		// Extrude the faces -- this just creates the new faces
		mesh.ExtrudeFaces();

		// Build normals of selected faces only		
		Tab<Point3> normals;
		if (!c) {
			normals.SetCount(mesh.getNumVerts());
			for (int i=0; i<mesh.getNumVerts(); i++) {
				normals[i] = Point3(0,0,0);
				}
			for (int i=0; i<mesh.getNumFaces(); i++) {
				if (mesh.faceSel[i]) {
					Point3 norm = 
						(mesh.verts[mesh.faces[i].v[1]]-mesh.verts[mesh.faces[i].v[0]]) ^
						(mesh.verts[mesh.faces[i].v[2]]-mesh.verts[mesh.faces[i].v[1]]);
					for (int j=0; j<3; j++) {				
						normals[mesh.faces[i].v[j]] += norm;
						}
					}
				}			
			for (int i=0; i<mesh.getNumVerts(); i++) {
				normals[i] = Normalize(normals[i]);
				}
		} else {
			// Compute the center point			
			base->GetValue(t,&center,iv,CTRL_ABSOLUTE);			
			}

		// Mark vertices used by selected faces
		BitArray sel;
		sel.SetSize(mesh.getNumVerts());
		for (int i=0; i<mesh.getNumFaces(); i++) {
			if (mesh.faceSel[i]) {
				for (int j=0; j<3; j++) sel.Set(mesh.faces[i].v[j],TRUE);
				}
			}

		// Move selected verts
		for (int i=0; i<mesh.getNumVerts(); i++) {
			if (sel[i]) {
				if (!c) {
					mesh.verts[i] += normals[i]*a;
				} else {
					Point3 vect = Normalize((mesh.verts[i] * (*mc.tm))
						- center);
					mesh.verts[i] += vect*a;
					}
				}
			}
		
		// Scale verts
		if (s!=100.0f) {
			s /= 100.0f;

			AdjEdgeList ae(mesh);
			AdjFaceList af(mesh,ae);
			FaceClusterList clust(mesh.faceSel,af);
			
			// Make sure each vertex is only scaled once.
			BitArray done;
			done.SetSize(mesh.getNumVerts());

			// scale each cluster independently
			for (int i=0; (DWORD)i<clust.count; i++) {
				// First determine cluster center
				Point3 cent(0,0,0);
				int ct=0;
				for (int j=0; j<mesh.getNumFaces(); j++) {
					if (clust[j]==(DWORD)i) {
						for (int k=0; k<3; k++) {
							cent += mesh.verts[mesh.faces[j].v[k]];
							ct++;
							}
						}
					}
				if (ct) cent /= float(ct);

				// Now scale the cluster about its center
				for (int j=0; j<mesh.getNumFaces(); j++) {
					if (clust[j]==(DWORD)i) {
						for (int k=0; k<3; k++) {
							int index = mesh.faces[j].v[k]; 
							if (done[index]) continue;
							done.Set(index);
							mesh.verts[index] = 
								(mesh.verts[index]-cent)*s + cent;							
							}
						}
					}
				}
			}
		
		mesh.InvalidateTopologyCache ();
		os->obj->UpdateValidity(GEOM_CHAN_NUM,iv);		
		}
	}
示例#5
0
int main(){
	
	ae();
}
示例#6
0
NS_IMETHODIMP
ImportLoader::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{
  AutoError ae(this);
  nsIPrincipal* principal = Principal();

  nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
  if (!channel) {
    return NS_ERROR_DOM_ABORT_ERR;
  }

  if (nsContentUtils::IsSystemPrincipal(principal)) {
    // We should never import non-system documents and run their scripts with system principal!
    nsCOMPtr<nsIPrincipal> channelPrincipal;
    nsContentUtils::GetSecurityManager()->GetChannelResultPrincipal(channel,
                                                                    getter_AddRefs(channelPrincipal));
    if (!nsContentUtils::IsSystemPrincipal(channelPrincipal)) {
      return NS_ERROR_FAILURE;
    }
  }
  channel->SetOwner(principal);

  nsAutoCString type;
  channel->GetContentType(type);
  if (!type.EqualsLiteral("text/html")) {
    NS_WARNING("ImportLoader wrong content type");
    return NS_ERROR_DOM_ABORT_ERR;
  }

  // The scope object is same for all the imports in an import tree,
  // let's get it form the import parent.
  nsCOMPtr<nsIGlobalObject> global = mImportParent->GetScopeObject();
  nsCOMPtr<nsIDOMDocument> importDoc;
  nsCOMPtr<nsIURI> baseURI = mImportParent->GetBaseURI();
  const nsAString& emptyStr = EmptyString();
  nsresult rv = NS_NewDOMDocument(getter_AddRefs(importDoc),
                                  emptyStr, emptyStr, nullptr, mURI,
                                  baseURI, principal, false, global,
                                  DocumentFlavorHTML);
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);

  // The imported document must know which master document it belongs to.
  mDocument = do_QueryInterface(importDoc);
  nsCOMPtr<nsIDocument> master = mImportParent->MasterDocument();
  mDocument->SetMasterDocument(master);

  // We want to inherit the sandbox flags and fullscreen enabled flag
  // from the master document.
  mDocument->SetSandboxFlags(master->GetSandboxFlags());

  // We have to connect the blank document we created with the channel we opened,
  // and create its own LoadGroup for it.
  nsCOMPtr<nsIStreamListener> listener;
  nsCOMPtr<nsILoadGroup> loadGroup;
  channel->GetLoadGroup(getter_AddRefs(loadGroup));
  nsCOMPtr<nsILoadGroup> newLoadGroup = do_CreateInstance(NS_LOADGROUP_CONTRACTID);
  NS_ENSURE_TRUE(newLoadGroup, NS_ERROR_OUT_OF_MEMORY);
  newLoadGroup->SetLoadGroup(loadGroup);
  rv = mDocument->StartDocumentLoad("import", channel, newLoadGroup,
                                    nullptr, getter_AddRefs(listener),
                                    true);
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);

  nsCOMPtr<nsIURI> originalURI;
  rv = channel->GetOriginalURI(getter_AddRefs(originalURI));
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);

  nsCOMPtr<nsIURI> URI;
  rv = channel->GetURI(getter_AddRefs(URI));
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);
  MOZ_ASSERT(URI, "URI of a channel should never be null");

  bool equals;
  rv = URI->Equals(originalURI, &equals);
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);

  if (!equals) {
    // In case of a redirection we must add the new URI to the import map.
    Manager()->AddLoaderWithNewURI(this, URI);
  }

  // Let's start the parser.
  mParserStreamListener = listener;
  rv = listener->OnStartRequest(aRequest, aContext);
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_ABORT_ERR);

  ae.Pass();
  return NS_OK;
}
示例#7
0
void dTensor1d::copyfrom(const dTensor1d& in)
{
  ae(b1,in.b1);
  dTensorBase::copyfrom(in);
}
示例#8
0
void dTensor4d::copyfrom(const dTensor4d& in)
{
  ae(b1,in.b1); ae(b2,in.b2); ae(b3,in.b3); ae(b4,in.b4);
  ae(e1,in.e1); ae(e2,in.e2); ae(e3,in.e3); ae(e4,in.e4);
  ae(s1,in.s1); ae(s2,in.s2); ae(s3,in.s3); ae(s4,in.s4);
  dTensorBase::copyfrom(in);
}
void DocumentExporter::exportCurrentScene(Scene *sce)
{
	PointerRNA sceneptr, unit_settings;
	PropertyRNA *system; /* unused , *scale; */

	clear_global_id_map();
	
	COLLADABU::NativeString native_filename =
	    COLLADABU::NativeString(std::string(this->export_settings->filepath), COLLADABU::NativeString::ENCODING_UTF8);
	COLLADASW::StreamWriter sw(native_filename);

	fprintf(stdout, "Collada export: %s\n", this->export_settings->filepath);

	// open <collada>
	sw.startDocument();

	// <asset>
	COLLADASW::Asset asset(&sw);

	RNA_id_pointer_create(&(sce->id), &sceneptr);
	unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
	system = RNA_struct_find_property(&unit_settings, "system");
	//scale = RNA_struct_find_property(&unit_settings, "scale_length");

	std::string unitname = "meter";
	float linearmeasure = RNA_float_get(&unit_settings, "scale_length");

	switch (RNA_property_enum_get(&unit_settings, system)) {
		case USER_UNIT_NONE:
		case USER_UNIT_METRIC:
			if (linearmeasure == 0.001f) {
				unitname = "millimeter";
			}
			else if (linearmeasure == 0.01f) {
				unitname = "centimeter";
			}
			else if (linearmeasure == 0.1f) {
				unitname = "decimeter";
			}
			else if (linearmeasure == 1.0f) {
				unitname = "meter";
			}
			else if (linearmeasure == 1000.0f) {
				unitname = "kilometer";
			}
			break;
		case USER_UNIT_IMPERIAL:
			if (linearmeasure == 0.0254f) {
				unitname = "inch";
			}
			else if (linearmeasure == 0.3048f) {
				unitname = "foot";
			}
			else if (linearmeasure == 0.9144f) {
				unitname = "yard";
			}
			break;
		default:
			break;
	}

	asset.setUnit(unitname, linearmeasure);
	asset.setUpAxisType(COLLADASW::Asset::Z_UP);
	if (U.author[0] != '\0') {
		asset.getContributor().mAuthor = U.author;
	}
	else {
		asset.getContributor().mAuthor = "Blender User";
	}
	char version_buf[128];
#ifdef WITH_BUILDINFO
	sprintf(version_buf, "Blender %d.%02d.%d r%s", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION, build_rev);
#else
	sprintf(version_buf, "Blender %d.%02d.%d", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION);
#endif
	asset.getContributor().mAuthoringTool = version_buf;
	asset.add();
	
	LinkNode *export_set = this->export_settings->export_set;
	// <library_cameras>
	if (bc_has_object_type(export_set, OB_CAMERA)) {
		CamerasExporter ce(&sw, this->export_settings);
		ce.exportCameras(sce);
	}
	
	// <library_lights>
	if (bc_has_object_type(export_set, OB_LAMP)) {
		LightsExporter le(&sw, this->export_settings);
		le.exportLights(sce);
	}

	// <library_images>
	ImagesExporter ie(&sw, this->export_settings);
	ie.exportImages(sce);
	
	// <library_effects>
	EffectsExporter ee(&sw, this->export_settings);
	ee.exportEffects(sce);
	
	// <library_materials>
	MaterialsExporter me(&sw, this->export_settings);
	me.exportMaterials(sce);

	// <library_geometries>
	if (bc_has_object_type(export_set, OB_MESH)) {
		GeometryExporter ge(&sw, this->export_settings);
		ge.exportGeom(sce);
	}

	// <library_animations>
	AnimationExporter ae(&sw, this->export_settings);
	ae.exportAnimations(sce);

	// <library_controllers>
	ArmatureExporter arm_exporter(&sw, this->export_settings);
	if (bc_has_object_type(export_set, OB_ARMATURE)) {
		arm_exporter.export_controllers(sce);
	}

	// <library_visual_scenes>
	SceneExporter se(&sw, &arm_exporter, this->export_settings);
	se.exportScene(sce);
	
	// <scene>
	std::string scene_name(translate_id(id_name(sce)));
	COLLADASW::Scene scene(&sw, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING,
	                                           scene_name));
	scene.add();
	
	// close <Collada>
	sw.endDocument();

}
示例#10
0
void SkDebugCanvas::drawTo(SkCanvas* canvas, int index, int m) {
    SkASSERT(!fCommandVector.isEmpty());
    SkASSERT(index < fCommandVector.count());

    int saveCount = canvas->save();

    SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize().width()),
                                       SkIntToScalar(canvas->getBaseLayerSize().height()));

    bool pathOpsMode = getAllowSimplifyClip();
    canvas->setAllowSimplifyClip(pathOpsMode);
    canvas->clear(SK_ColorWHITE);
    canvas->resetMatrix();
    if (!windowRect.isEmpty()) {
        canvas->clipRect(windowRect, SkRegion::kReplace_Op);
    }
    this->applyUserTransform(canvas);

    if (fPaintFilterCanvas) {
        fPaintFilterCanvas->addCanvas(canvas);
        canvas = fPaintFilterCanvas.get();

    }

    if (fMegaVizMode) {
        this->markActiveCommands(index);
    }

#if SK_SUPPORT_GPU
    // If we have a GPU backend we can also visualize the batching information
    GrAuditTrail* at = nullptr;
    if (fDrawGpuBatchBounds || m != -1) {
        at = this->getAuditTrail(canvas);
    }
#endif

    for (int i = 0; i <= index; i++) {
        if (i == index && fFilter) {
            canvas->clear(0xAAFFFFFF);
        }

#if SK_SUPPORT_GPU
        // We need to flush any pending operations, or they might batch with commands below.
        // Previous operations were not registered with the audit trail when they were
        // created, so if we allow them to combine, the audit trail will fail to find them.
        canvas->flush();

        GrAuditTrail::AutoCollectBatches* acb = nullptr;
        if (at) {
            acb = new GrAuditTrail::AutoCollectBatches(at, i);
        }
#endif

        if (fCommandVector[i]->isVisible()) {
            if (fMegaVizMode && fCommandVector[i]->active()) {
                // "active" commands execute their visualization behaviors:
                //     All active saveLayers get replaced with saves so all draws go to the
                //     visible canvas.
                //     All active culls draw their cull box
                fCommandVector[i]->vizExecute(canvas);
            } else {
                fCommandVector[i]->setUserMatrix(fUserMatrix);
                fCommandVector[i]->execute(canvas);
            }
        }
#if SK_SUPPORT_GPU
        if (at && acb) {
            delete acb;
        }
#endif
    }

    if (SkColorGetA(fClipVizColor) != 0) {
        canvas->save();
        #define LARGE_COORD 1000000000
        canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD),
                       SkRegion::kReverseDifference_Op);
        SkPaint clipPaint;
        clipPaint.setColor(fClipVizColor);
        canvas->drawPaint(clipPaint);
        canvas->restore();
    }

    if (fMegaVizMode) {
        canvas->save();
        // nuke the CTM
        canvas->resetMatrix();
        // turn off clipping
        if (!windowRect.isEmpty()) {
            SkRect r = windowRect;
            r.outset(SK_Scalar1, SK_Scalar1);
            canvas->clipRect(r, SkRegion::kReplace_Op);
        }
        // visualize existing clips
        SkDebugClipVisitor visitor(canvas);

        canvas->replayClips(&visitor);

        canvas->restore();
    }
    if (pathOpsMode) {
        this->resetClipStackData();
        const SkClipStack* clipStack = canvas->getClipStack();
        SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart);
        const SkClipStack::Element* element;
        SkPath devPath;
        while ((element = iter.next())) {
            SkClipStack::Element::Type type = element->getType();
            SkPath operand;
            if (type != SkClipStack::Element::kEmpty_Type) {
               element->asPath(&operand);
            }
            SkRegion::Op elementOp = element->getOp();
            this->addClipStackData(devPath, operand, elementOp);
            if (elementOp == SkRegion::kReplace_Op) {
                devPath = operand;
            } else {
                Op(devPath, operand, (SkPathOp) elementOp, &devPath);
            }
        }
        this->lastClipStackData(devPath);
    }
    fMatrix = canvas->getTotalMatrix();
    if (!canvas->getClipDeviceBounds(&fClip)) {
        fClip.setEmpty();
    }

    canvas->restoreToCount(saveCount);

    if (fPaintFilterCanvas) {
        fPaintFilterCanvas->removeAll();
    }

#if SK_SUPPORT_GPU
    // draw any batches if required and issue a full reset onto GrAuditTrail
    if (at) {
        // just in case there is global reordering, we flush the canvas before querying
        // GrAuditTrail
        GrAuditTrail::AutoEnable ae(at);
        canvas->flush();

        // we pick three colorblind-safe colors, 75% alpha
        static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A);
        static const SkColor kOpBatchBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C);
        static const SkColor kOtherBatchBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00);

        // get the render target of the top device so we can ignore batches drawn offscreen
        SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_testing();
        SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd);
        uint32_t rtID = gbd->accessRenderTarget()->getUniqueID();

        // get the bounding boxes to draw
        SkTArray<GrAuditTrail::BatchInfo> childrenBounds;
        if (m == -1) {
            at->getBoundsByClientID(&childrenBounds, index);
        } else {
            // the client wants us to draw the mth batch
            at->getBoundsByBatchListID(&childrenBounds.push_back(), m);
        }
        SkPaint paint;
        paint.setStyle(SkPaint::kStroke_Style);
        paint.setStrokeWidth(1);
        for (int i = 0; i < childrenBounds.count(); i++) {
            if (childrenBounds[i].fRenderTargetUniqueID != rtID) {
                // offscreen draw, ignore for now
                continue;
            }
            paint.setColor(kTotalBounds);
            canvas->drawRect(childrenBounds[i].fBounds, paint);
            for (int j = 0; j < childrenBounds[i].fBatches.count(); j++) {
                const GrAuditTrail::BatchInfo::Batch& batch = childrenBounds[i].fBatches[j];
                if (batch.fClientID != index) {
                    paint.setColor(kOtherBatchBounds);
                } else {
                    paint.setColor(kOpBatchBounds);
                }
                canvas->drawRect(batch.fBounds, paint);
            }
        }
    }
#endif
    this->cleanupAuditTrail(canvas);
}
void T (int j) {
    int g,e,m,aa;
    g=1;
    if( d == 34) {
        H(v);
        while( h!=34) {
            Y ();
            *(char*) v++=h;
            o ();
        }
        *(char*) v=0;
        v=v +4&-4;
        o ();
        ad();
    }
    else {
        aa=C;
        m= z;
        e=d;
        ad();
        if( e == 2) {
            H(m);
        }
        else if( aa == 2) {
            T(0);
            s(185,0);
            if( e == 33)Z(m);
            else ae( m);
        }
        else if( e == 40) {
            w ();
            ad();
        }
        else if( e == 42) {
            ad();
            e=d;
            ad();
            ad();
            if( d == 42) {
                ad();
                ad();
                ad();
                ad();
                e=0;
            }
            ad();
            T(0);
            if( d == 61) {
                ad();
                ae( 80);
                w ();
                ae( 89);
                ae( 392+(e == 256));
            }
            else if( e) {
                if( e == 256)ae( 139);
                else ae( 48655);
                q++;
            }
        }
        else if( e == 38) {
            N(10,*(int*) d);
            ad();
        }
        else {
            g=*(int*) e;
            if(!g)g=dlsym(0,M);
            if( d == 61&j) {
                ad();
                w ();
                N(6,g);
            }
            else if( d!= 40) {
                N(8,g);
                if( C == 11) {
                    N(0,g);
                    ae( z);
                    ad();
                }
            }
        }
    }
    if( d == 40) {
        if( g == 1)ae( 80);
        m= s(60545,0);
        ad();
        j=0;
        while( d!= 41) {
            w ();
            s(2393225,j);
            if( d == 44)ad();
            j=j +4;
        }
        *(int*) m= j;
        ad();
        if(!g) {
            e=e +4;
            *(int*) e=s(232,*(int*) e);
        }
        else if( g == 1) {
            s(2397439,j);
            j=j +4;
        }
        else {
            s(232,g-q-5);
        }
        if( j)s(50305,j);
    }
}
void N(int j, int e) {
    ae(j + 131);
    s((e > -512 && e < 512) << 7 | 5, e);
}
int S(int j, int e) {
    ae(1032325);
    return s(132 + j, e);
}
示例#14
0
文件: main.cpp 项目: rdevon/DBN
int main (int argc, char * argv[])
{
   
   std::streambuf *psbuf = NULL;
   std::ofstream log_stream;
   std::streambuf *pStreambuf = std::cout.rdbuf();
   
   //--------------RNG INIT STUFF
   srand((unsigned)time(0));
   long seed;
   r = gsl_rng_alloc (gsl_rng_rand48);     // pick random number generator
   seed = time (NULL) * getpid();
   gsl_rng_set (r, seed);                  // set seed
   // TESTING AREA
   
   //---------------
   DBN *dbn;
   
   if (command_option_exists(argv, argv+argc, "-n")) {
      dbn = return_network();
      std::cout << dbn << std::endl;
      std::cout << "Ready to learn" << std::endl;
      std::cout << "If you are using visualization:" << std::endl;
      std::cout << "'V': pauses visualization" << std::endl;
      std::cout << "<SPACE>: pauses learning" << std::endl;
      std::cout << "'+'/'-' increases/decreases learning rate" << std::endl;
      std::cout << "'['/']' increases/decreases output threshold" << std::endl;
      std::cout << "'L' stops learning for layer (skips to next if any)" << std::endl;
      std::cout << "Current visualization is the features displayed on top with the plot of the reconstruction cost in the box (gl text not supported yet)" << std::endl;
      std::cout << "Press <ENTER> to start learning: ";
      std::cin.get();
   }
   else if (command_option_exists(argv, argv+argc, "-l")) {
      std::string filename = get_command_line(argv, argv+argc, "-l");
      MLP mlp = load_MLP(filename);
      dbn = new DBN(mlp);
      dbn->data_layers.clear();
      dbn->view();
      exit(EXIT_SUCCESS);
   }
   else if (command_option_exists(argv, argv+argc, "-f")) {
      if (argc != 3) {
         print_usage();
         exit(EXIT_FAILURE);
      }
      //Initialization, time, logfile stuff, etc.
      time_t t = time(0);   // get time now
      struct tm * the_time = localtime( & t );
      mkdir(out_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
      out_path += convert_to_string(*the_time) + "/";
      mkdir((out_path).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
      
      std::string filename = get_command_line(argv, argv+argc, "-f");
      dbn = return_aod_network(filename, log_stream, psbuf);
      
   }
   else if (command_option_exists(argv, argv+argc, "-F")) {
      
      std::string filename = get_command_line(argv, argv+argc, "-F");
      MLP mlp = load_MLP(filename); 
      Autoencoder ae(mlp);
      ae.name = (mlp).name + "fine_tuning";
      Gradient_Descent gd(0);
      gd.teachAE(ae);
      MLP ae_mlp;
      save(ae);
      exit(EXIT_SUCCESS);
   }
   else if (command_option_exists(argv, argv+argc, "-stack")) {
      std::string filename = get_command_line(argv, argv+argc, "-stack");
      dbn = load_and_stack(filename, log_stream, psbuf);
   }
   else {
      print_usage();
      exit(EXIT_SUCCESS);
   }
   ContrastiveDivergence cd(1000);
   dbn->learn(cd);
   std::cout.rdbuf(pStreambuf);
   log_stream.close();
   exit(1);
   return 0;
}
示例#15
0
int
main(int argc, char **argv)
{
#if defined(_DEBUG)
    {
#endif
        boost::shared_ptr<analyser_environment_t> ae(
            new analyser_environment_t);

        if (false == ae->parse_command_line(argc, argv))
        {
            return 1;
        }

        std::list<keyword_t> keywords;
        keywords.push_back(keyword_t(L"_apostrophe", KEYWORD_POS_BACK));

        try
        {
            // ====================================================
            //                    read grammar
            // ====================================================
            ae->read_grammar(keywords);

            //ae->dump_tree(L"1_orig_tree.dot");
            assert(true == ae->traverse_all_nodes(check_not_optional, 0, 0));

            // ====================================================
            //                  link non-terminal
            // ====================================================
            if (false == ae->traverse_all_nodes(link_nonterminal, 0, 0))
            {
                return 1;
            }
            else
            {
                //ae->dump_tree(L"2_link_nonterminal.dot");
            }

            ae->check_nonterminal_linking();

            if (false == ae->check_grammar())
            {
                ae->log(L"<ERROR>: grammar checking failed.\n");
                return 1;
            }
        }
        catch (ga_exception_t const &)
        {
            ae->log(L"<ERROR>: wrong grammar file.\n");
            return 1;
        }

        assert(true == ae->traverse_all_nodes(check_if_regex_info_is_empty, 0, 0));
        assert(true == ae->traverse_all_nodes(check_if_regex_info_is_correct_for_traverse_all_nodes, 0, 0));

        // After regex OR statements expansion, I can delete those
        // regexs of type REGEX_TYPE_ONE.
        //
        // Ex:
        //
        // A (B C | D) E
        //
        // will become:
        //
        // A (B C) E
        // A (D) E
        //
        // And this will be equivalent to the following form:
        //
        // A B C E
        // A D E
        ae->traverse_all_nodes(delete_regex_type_one, 0, 0);

        // I have to expand regex info before the restoring
        // below.
        //
        // Ex:
        //
        // After reading the grammar, the contents of the
        // regex_info & tmp_regex_info are as the following:
        //
        //                  ((a b (c (d e)*)* f)* g)
        // -------------------------------------------
        // regex_info
        // tmp_regex_info     .    .  .              <- back()
        //                    .                      <- front()
        //
        // There are 2 elements in the 'tmp_regex_info' of node
        // 'a', and 1 element in the 'tmp_regex_info' of node
        // 'c'.
        //
        // If I restore the regex first, and then expand each
        // regex by iterate all the nodes in a regex and
        // push_back() & push_front() each regex_info at the
        // starting node of that regex into the rest nodes of
        // that regex, then the problem will be occurred at node
        // 'd'. When I expand the regex starting at node 'a',
        // the 'tmp_regex_info' of node 'd' will become:
        //
        // back() -> .  <- from node 'a'
        //           .  <- from node 'a'
        //           .  <- original
        //
        // Then if I want to expand the regex starting from node
        // 'c', then the desired result will be:
        //
        // back() -> .  <- from node 'a'
        //           .  <- from node 'a'
        //           .  <- from node 'c'
        //           .  <- original
        //
        // This will force me to remember the front of
        // the latest expansion operation.
        //
        // However, if I expand the regex before the restoring,
        // then I just need to use push_front() all the time.
        ae->fill_regex_info_to_relative_nodes_for_each_regex_group();

        // restore each node's 'regex_info' from
        // 'tmp_regex_info'.
        ae->restore_regex_info();

        // ====================================================
        //               remove useless rules
        // ====================================================
        ae->log(L"<INFO>: Removing useless rules.\n");
        ae->remove_useless_rule();
        if (0 == ae->top_level_nodes().size())
        {
            return 1;
        }

        ae->check_nonterminal_linking();

        // ====================================================
        //                detect left recursion
        // ====================================================
        std::list<std::list<node_t *> > left_recursion_set;

        bool const has_left_recursion = ae->detect_left_recursion(left_recursion_set);

        if ((true == has_left_recursion) ||
        (true == ae->use_paull_algo_to_remove_left_recursion()))
        {
            // Paull's algorithm (remove left recursion)
            if (true == ae->use_paull_algo_to_remove_left_recursion())
            {
                // ====================================================
                //            detect nullable non-terminals
                // ====================================================
                ae->log(L"<INFO>: Detect nullable nonterminals.\n");
                ae->detect_nullable_nonterminal();
                //ae->dump_tree(L"3_detect_nullable.dot");

                ae->check_nonterminal_linking();

                // ====================================================
                //           remove epsilon production
                // ====================================================
                ae->remove_epsilon_production();
                if (false == ae->check_grammar())
                {
                    ae->log(L"<ERROR>: grammar checking failed.\n");
                    return 1;
                }

                ae->check_nonterminal_linking();

                assert(true == ae->traverse_all_nodes(check_no_epsilon, 0, 0));
                assert(true == ae->traverse_all_nodes(check_not_optional, 0, 0));

                //ae->dump_tree(L"4_remove_epsilon.dot");

                // ====================================================
                //              remove direct cyclic
                // ====================================================
                ae->log(L"<INFO>: Removing direct cyclic.\n");
                ae->remove_direct_cyclic();

                if (0 == ae->top_level_nodes().size())
                {
                    ae->log(L"<WARN>: Reach an empty grammar after removing direct cyclic.\n");
                    return 0;
                }

                ae->check_nonterminal_linking();

                assert(true == ae->check_grammar());
                assert(true == ae->traverse_all_nodes(check_no_epsilon, 0, 0));

                //ae->dump_tree(L"5_remove_direct_cyclic.dot");

                // ====================================================
                //              detect cyclic non-terminals
                // ====================================================
                ae->log(L"<INFO>: Detect cyclic nonterminals.\n");
                ae->detect_cyclic_nonterminal();
                //ae->dump_tree(L"6_detect_cyclic.dot");

                ae->check_nonterminal_linking();

                // ====================================================
                //               remove cyclic
                // ====================================================
                ae->log(L"<INFO>: Removing cyclic.\n");
                ae->remove_cyclic();

                if (0 == ae->top_level_nodes().size())
                {
                    ae->log(L"<WARN>: Reach an empty grammar after removing cyclic.\n");
                    return 0;
                }

                assert(true == ae->check_grammar());
                ae->check_nonterminal_linking();

                ae->traverse_all_nodes(clear_cyclic_set, 0, 0);
                ae->detect_cyclic_nonterminal();

                assert(true == ae->traverse_all_nodes(check_not_cyclic, 0, 0));
                assert(true == ae->traverse_all_nodes(check_no_epsilon, 0, 0));
                //ae->dump_tree(L"7_remove_cyclic.dot");

                // ====================================================
                //               find left corners
                // ====================================================
                ae->find_left_corners();
                ae->order_nonterminal_decrease_number_of_distinct_left_corner();

                ae->check_nonterminal_linking();

                // ====================================================
                //               remove left recursion
                // ====================================================
                ae->log(L"<INFO>: Removing left recursion.\n");
                ae->remove_left_recur();

                assert(true == ae->check_grammar());

                //ae->dump_tree(L"8_remove_left_recurison.dot");
                ae->check_nonterminal_linking();

                // ====================================================
                //               remove useless rule
                // ====================================================
                ae->log(L"<INFO>: Removing useless rule.\n");
                ae->remove_useless_rule();

#if defined(_DEBUG)
                // ====================================================
                //                detect left recursion
                // ====================================================
                {
                    left_recursion_set.clear();

                    bool const has_left_recursion = ae->detect_left_recursion(left_recursion_set);

                    assert(false == has_left_recursion);
                }
#endif
            }
            else
            {
                ae->log(L"<ERROR>: There are left recursions among:\n");

                int i = 0;

                BOOST_FOREACH(std::list<node_t *> const &sets, left_recursion_set)
                {
                    ae->log(L"%d) ", i);

                    BOOST_FOREACH(node_t const * const node, sets)
                    {
                        ae->log(L"%s ", node->name().c_str());
                    }

                    ae->log(L"\n");
                }

                return 1;
            }
        }
示例#16
0
  void GLUE2::ParseExecutionTargets(XMLNode glue2tree, std::list<ComputingServiceType>& targets) {

    XMLNode GLUEService = glue2tree;
    if(GLUEService.Name() != "ComputingService") {
      GLUEService = glue2tree["ComputingService"];
    }

    for (; GLUEService; ++GLUEService) {
      ComputingServiceType cs;

      if (GLUEService["ID"]) {
        cs->ID = (std::string)GLUEService["ID"];
      }
      if (GLUEService["Name"]) {
        cs->Name = (std::string)GLUEService["Name"];
      }
      if (GLUEService["Capability"]) {
        for (XMLNode n = GLUEService["Capability"]; n; ++n) {
          cs->Capability.insert((std::string)n);
        }
      }
      if (GLUEService["Type"]) {
        cs->Type = (std::string)GLUEService["Type"];
      } else {
        logger.msg(VERBOSE, "The Service doesn't advertise its Type.");
      }
      if (GLUEService["QualityLevel"]) {
        cs->QualityLevel = (std::string)GLUEService["QualityLevel"];
      } else {
        logger.msg(VERBOSE, "The ComputingService doesn't advertise its Quality Level.");
      }
      if (GLUEService["TotalJobs"]) {
        cs->TotalJobs = stringtoi((std::string)GLUEService["TotalJobs"]);
      }
      if (GLUEService["RunningJobs"]) {
        cs->RunningJobs = stringtoi((std::string)GLUEService["RunningJobs"]);
      }
      if (GLUEService["WaitingJobs"]) {
        cs->WaitingJobs = stringtoi((std::string)GLUEService["WaitingJobs"]);
      }
      if (GLUEService["StagingJobs"]) {
        cs->StagingJobs = stringtoi((std::string)GLUEService["StagingJobs"]);
      }
      if (GLUEService["SuspendedJobs"]) {
        cs->SuspendedJobs = stringtoi((std::string)GLUEService["SuspendedJobs"]);
      }
      if (GLUEService["PreLRMSWaitingJobs"]) {
        cs->PreLRMSWaitingJobs = stringtoi((std::string)GLUEService["PreLRMSWaitingJobs"]);
      }
      // The GLUE2 specification does not have attribute ComputingService.LocalRunningJobs
      //if (GLUEService["LocalRunningJobs"]) {
      //  cs->LocalRunningJobs = stringtoi((std::string)GLUEService["LocalRunningJobs"]);
      //}
      // The GLUE2 specification does not have attribute ComputingService.LocalWaitingJobs
      //if (GLUEService["LocalWaitingJobs"]) {
      //  cs->LocalWaitingJobs = stringtoi((std::string)GLUEService["LocalWaitingJobs"]);
      //}
      // The GLUE2 specification does not have attribute ComputingService.LocalSuspendedJobs
      //if (GLUEService["LocalSuspendedJobs"]) {
      //  cs->LocalWaitingJobs = stringtoi((std::string)GLUEService["LocalSuspendedJobs"]);
      //}


      XMLNode xmlCENode = GLUEService["ComputingEndpoint"];
      int endpointID = 0;
      for(;(bool)xmlCENode;++xmlCENode) {
        ComputingEndpointType ComputingEndpoint;
        if (xmlCENode["URL"]) {
          ComputingEndpoint->URLString = (std::string)xmlCENode["URL"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint has no URL.");
        }
        if (xmlCENode["HealthState"]) {
          ComputingEndpoint->HealthState = (std::string)xmlCENode["HealthState"];
        } else {
          logger.msg(VERBOSE, "The Service advertises no Health State.");
        }
        if (xmlCENode["HealthStateInfo"]) {
          ComputingEndpoint->HealthStateInfo = (std::string)xmlCENode["HealthStateInfo"];
        }
        if (xmlCENode["Capability"]) {
          for (XMLNode n = xmlCENode["Capability"]; n; ++n) {
            ComputingEndpoint->Capability.insert((std::string)n);
          }
        }
        if (xmlCENode["QualityLevel"]) {
          ComputingEndpoint->QualityLevel = (std::string)xmlCENode["QualityLevel"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint doesn't advertise its Quality Level.");
        }

        if (xmlCENode["Technology"]) {
          ComputingEndpoint->Technology = (std::string)xmlCENode["Technology"];
        }
        if (xmlCENode["InterfaceName"]) {
          ComputingEndpoint->InterfaceName = lower((std::string)xmlCENode["InterfaceName"]);
        } else if (xmlCENode["Interface"]) { // No such attribute according to GLUE2 document. Legacy/backward compatibility?
          ComputingEndpoint->InterfaceName = lower((std::string)xmlCENode["Interface"]);
        } else {
          logger.msg(VERBOSE, "The ComputingService doesn't advertise its Interface.");
        }
        if (xmlCENode["InterfaceVersion"]) {
          for (XMLNode n = xmlCENode["InterfaceVersion"]; n; ++n) {
            ComputingEndpoint->InterfaceVersion.push_back((std::string)n);
          }
        }
        if (xmlCENode["InterfaceExtension"]) {
          for (XMLNode n = xmlCENode["InterfaceExtension"]; n; ++n) {
            ComputingEndpoint->InterfaceExtension.push_back((std::string)n);
          }
        }
        if (xmlCENode["SupportedProfile"]) {
          for (XMLNode n = xmlCENode["SupportedProfile"]; n; ++n) {
            ComputingEndpoint->SupportedProfile.push_back((std::string)n);
          }
        }
        if (xmlCENode["Implementor"]) {
          ComputingEndpoint->Implementor = (std::string)xmlCENode["Implementor"];
        }
        if (xmlCENode["ImplementationName"]) {
          if (xmlCENode["ImplementationVersion"]) {
            ComputingEndpoint->Implementation =
              Software((std::string)xmlCENode["ImplementationName"],
                       (std::string)xmlCENode["ImplementationVersion"]);
          } else {
            ComputingEndpoint->Implementation = Software((std::string)xmlCENode["ImplementationName"]);
          }
        }
        if (xmlCENode["ServingState"]) {
          ComputingEndpoint->ServingState = (std::string)xmlCENode["ServingState"];
        } else {
          logger.msg(VERBOSE, "The ComputingEndpoint doesn't advertise its Serving State.");
        }
        if (xmlCENode["IssuerCA"]) {
          ComputingEndpoint->IssuerCA = (std::string)xmlCENode["IssuerCA"];
        }
        if (xmlCENode["TrustedCA"]) {
          XMLNode n = xmlCENode["TrustedCA"];
          while (n) {
            // Workaround to drop non-conforming records generated by EGI services
            std::string subject = (std::string)n;
            if(CheckConformingDN(subject)) {
              ComputingEndpoint->TrustedCA.push_back(subject);
            }
            ++n; //The increment operator works in an unusual manner (returns void)
          }
        }
        if (xmlCENode["DowntimeStart"]) {
          ComputingEndpoint->DowntimeStarts = (std::string)xmlCENode["DowntimeStart"];
        }
        if (xmlCENode["DowntimeEnd"]) {
          ComputingEndpoint->DowntimeEnds = (std::string)xmlCENode["DowntimeEnd"];
        }
        if (xmlCENode["Staging"]) {
          ComputingEndpoint->Staging = (std::string)xmlCENode["Staging"];
        }
        if (xmlCENode["JobDescription"]) {
          for (XMLNode n = xmlCENode["JobDescription"]; n; ++n) {
            ComputingEndpoint->JobDescriptions.push_back((std::string)n);
          }
        }

        if (xmlCENode["TotalJobs"]) {
          ComputingEndpoint->TotalJobs = stringtoi((std::string)xmlCENode["TotalJobs"]);
        }
        if (xmlCENode["RunningJobs"]) {
          ComputingEndpoint->RunningJobs = stringtoi((std::string)xmlCENode["RunningJobs"]);
        }
        if (xmlCENode["WaitingJobs"]) {
          ComputingEndpoint->WaitingJobs = stringtoi((std::string)xmlCENode["WaitingJobs"]);
        }
        if (xmlCENode["StagingJobs"]) {
          ComputingEndpoint->StagingJobs = stringtoi((std::string)xmlCENode["StagingJobs"]);
        }
        if (xmlCENode["SuspendedJobs"]) {
          ComputingEndpoint->SuspendedJobs = stringtoi((std::string)xmlCENode["SuspendedJobs"]);
        }
        if (xmlCENode["PreLRMSWaitingJobs"]) {
          ComputingEndpoint->PreLRMSWaitingJobs = stringtoi((std::string)xmlCENode["PreLRMSWaitingJobs"]);
        }
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalRunningJobs
        //if (xmlCENode["LocalRunningJobs"]) {
        //  ComputingEndpoint->LocalRunningJobs = stringtoi((std::string)xmlCENode["LocalRunningJobs"]);
        //}
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalWaitingJobs
        //if (xmlCENode["LocalWaitingJobs"]) {
        //  ComputingEndpoint->LocalWaitingJobs = stringtoi((std::string)xmlCENode["LocalWaitingJobs"]);
        //}
        // The GLUE2 specification does not have attribute ComputingEndpoint.LocalSuspendedJobs
        //if (xmlCENode["LocalSuspendedJobs"]) {
        //  ComputingEndpoint->LocalSuspendedJobs = stringtoi((std::string)xmlCENode["LocalSuspendedJobs"]);
        //}

        cs.ComputingEndpoint.insert(std::pair<int, ComputingEndpointType>(endpointID++, ComputingEndpoint));
      }

      XMLNode xComputingShare = GLUEService["ComputingShare"];
      int shareID = 0;
      for (;(bool)xComputingShare;++xComputingShare) {
        ComputingShareType ComputingShare;

        if (xComputingShare["FreeSlots"]) {
          ComputingShare->FreeSlots = stringtoi((std::string)xComputingShare["FreeSlots"]);
        }
        if (xComputingShare["FreeSlotsWithDuration"]) {
          // Format: ns[:t] [ns[:t]]..., where ns is number of slots and t is the duration.
          ComputingShare->FreeSlotsWithDuration.clear();

          const std::string fswdValue = (std::string)xComputingShare["FreeSlotsWithDuration"];
          std::list<std::string> fswdList;
          tokenize(fswdValue, fswdList);
          for (std::list<std::string>::iterator it = fswdList.begin();
               it != fswdList.end(); it++) {
            std::list<std::string> fswdPair;
            tokenize(*it, fswdPair, ":");
            long duration = LONG_MAX;
            int freeSlots = 0;
            if (fswdPair.size() > 2 || !stringto(fswdPair.front(), freeSlots) || (fswdPair.size() == 2 && !stringto(fswdPair.back(), duration)) ) {
              logger.msg(VERBOSE, "The \"FreeSlotsWithDuration\" attribute published by \"%s\" is wrongly formatted. Ignoring it.");
              logger.msg(DEBUG, "Wrong format of the \"FreeSlotsWithDuration\" = \"%s\" (\"%s\")", fswdValue, *it);
              continue;
            }

            ComputingShare->FreeSlotsWithDuration[Period(duration)] = freeSlots;
          }
        }
        if (xComputingShare["UsedSlots"]) {
          ComputingShare->UsedSlots = stringtoi((std::string)xComputingShare["UsedSlots"]);
        }
        if (xComputingShare["RequestedSlots"]) {
          ComputingShare->RequestedSlots = stringtoi((std::string)xComputingShare["RequestedSlots"]);
        }
        if (xComputingShare["Name"]) {
          ComputingShare->Name = (std::string)xComputingShare["Name"];
        }
        if (xComputingShare["MaxWallTime"]) {
          ComputingShare->MaxWallTime = (std::string)xComputingShare["MaxWallTime"];
        }
        if (xComputingShare["MaxTotalWallTime"]) {
          ComputingShare->MaxTotalWallTime = (std::string)xComputingShare["MaxTotalWallTime"];
        }
        if (xComputingShare["MinWallTime"]) {
          ComputingShare->MinWallTime = (std::string)xComputingShare["MinWallTime"];
        }
        if (xComputingShare["DefaultWallTime"]) {
          ComputingShare->DefaultWallTime = (std::string)xComputingShare["DefaultWallTime"];
        }
        if (xComputingShare["MaxCPUTime"]) {
          ComputingShare->MaxCPUTime = (std::string)xComputingShare["MaxCPUTime"];
        }
        if (xComputingShare["MaxTotalCPUTime"]) {
          ComputingShare->MaxTotalCPUTime = (std::string)xComputingShare["MaxTotalCPUTime"];
        }
        if (xComputingShare["MinCPUTime"]) {
          ComputingShare->MinCPUTime = (std::string)xComputingShare["MinCPUTime"];
        }
        if (xComputingShare["DefaultCPUTime"]) {
          ComputingShare->DefaultCPUTime = (std::string)xComputingShare["DefaultCPUTime"];
        }
        if (xComputingShare["MaxTotalJobs"]) {
          ComputingShare->MaxTotalJobs = stringtoi((std::string)xComputingShare["MaxTotalJobs"]);
        }
        if (xComputingShare["MaxRunningJobs"]) {
          ComputingShare->MaxRunningJobs = stringtoi((std::string)xComputingShare["MaxRunningJobs"]);
        }
        if (xComputingShare["MaxWaitingJobs"]) {
          ComputingShare->MaxWaitingJobs = stringtoi((std::string)xComputingShare["MaxWaitingJobs"]);
        }
        if (xComputingShare["MaxPreLRMSWaitingJobs"]) {
          ComputingShare->MaxPreLRMSWaitingJobs = stringtoi((std::string)xComputingShare["MaxPreLRMSWaitingJobs"]);
        }
        if (xComputingShare["MaxUserRunningJobs"]) {
          ComputingShare->MaxUserRunningJobs = stringtoi((std::string)xComputingShare["MaxUserRunningJobs"]);
        }
        if (xComputingShare["MaxSlotsPerJob"]) {
          ComputingShare->MaxSlotsPerJob = stringtoi((std::string)xComputingShare["MaxSlotsPerJob"]);
        }
        if (xComputingShare["MaxStageInStreams"]) {
          ComputingShare->MaxStageInStreams = stringtoi((std::string)xComputingShare["MaxStageInStreams"]);
        }
        if (xComputingShare["MaxStageOutStreams"]) {
          ComputingShare->MaxStageOutStreams = stringtoi((std::string)xComputingShare["MaxStageOutStreams"]);
        }
        if (xComputingShare["SchedulingPolicy"]) {
          ComputingShare->SchedulingPolicy = (std::string)xComputingShare["SchedulingPolicy"];
        }
        if (xComputingShare["MaxMainMemory"]) {
          ComputingShare->MaxMainMemory = stringtoi((std::string)xComputingShare["MaxMainMemory"]);
        }
        if (xComputingShare["MaxVirtualMemory"]) {
          ComputingShare->MaxVirtualMemory = stringtoi((std::string)xComputingShare["MaxVirtualMemory"]);
        }
        if (xComputingShare["MaxDiskSpace"]) {
          ComputingShare->MaxDiskSpace = stringtoi((std::string)xComputingShare["MaxDiskSpace"]);
        }
        if (xComputingShare["DefaultStorageService"]) {
          ComputingShare->DefaultStorageService = (std::string)xComputingShare["DefaultStorageService"];
        }
        if (xComputingShare["Preemption"]) {
          ComputingShare->Preemption = ((std::string)xComputingShare["Preemption"] == "true") ? true : false;
        }
        if (xComputingShare["EstimatedAverageWaitingTime"]) {
          ComputingShare->EstimatedAverageWaitingTime = (std::string)xComputingShare["EstimatedAverageWaitingTime"];
        }
        if (xComputingShare["EstimatedWorstWaitingTime"]) {
          ComputingShare->EstimatedWorstWaitingTime = stringtoi((std::string)xComputingShare["EstimatedWorstWaitingTime"]);
        }
        if (xComputingShare["ReservationPolicy"]) {
          ComputingShare->ReservationPolicy = stringtoi((std::string)xComputingShare["ReservationPolicy"]);
        }

        cs.ComputingShare.insert(std::pair<int, ComputingShareType>(shareID++, ComputingShare));
      }

      /*
       * A ComputingShare is linked to multiple ExecutionEnvironments.
       * Due to bug 2101 multiple ExecutionEnvironments per ComputingShare
       * will be ignored. The ExecutionEnvironment information will only be
       * stored if there is one ExecutionEnvironment associated with a
       * ComputingShare.
       */
      /*
       * TODO: Store ExecutionEnvironment information in the list of
       * ExecutionEnvironmentType objects and issue a warning when the
       * resources published in multiple ExecutionEnvironment are
       * requested in a job description document.
       */

      int managerID = 0;
      for (XMLNode xComputingManager = GLUEService["ComputingManager"]; (bool)xComputingManager; ++xComputingManager) {
        ComputingManagerType ComputingManager;
        if (xComputingManager["ProductName"]) {
          ComputingManager->ProductName = (std::string)xComputingManager["ProductName"];
        }
        // The GlUE2 specification does not have attribute ComputingManager.Type
        //if (xComputingManager["Type"]) {
        //  ComputingManager->Type = (std::string)xComputingManager["Type"];
        //}
        if (xComputingManager["ProductVersion"]) {
          ComputingManager->ProductVersion = (std::string)xComputingManager["ProductVersion"];
        }
        if (xComputingManager["Reservation"]) {
          ComputingManager->Reservation = ((std::string)xComputingManager["Reservation"] == "true");
        }
        if (xComputingManager["BulkSubmission"]) {
          ComputingManager->BulkSubmission = ((std::string)xComputingManager["BulkSubmission"] == "true");
        }
        if (xComputingManager["TotalPhysicalCPUs"]) {
          ComputingManager->TotalPhysicalCPUs = stringtoi((std::string)xComputingManager["TotalPhysicalCPUs"]);
        }
        if (xComputingManager["TotalLogicalCPUs"]) {
          ComputingManager->TotalLogicalCPUs = stringtoi((std::string)xComputingManager["TotalLogicalCPUs"]);
        }
        if (xComputingManager["TotalSlots"]) {
          ComputingManager->TotalSlots = stringtoi((std::string)xComputingManager["TotalSlots"]);
        }
        if (xComputingManager["Homogeneous"]) {
          ComputingManager->Homogeneous = ((std::string)xComputingManager["Homogeneous"] == "true");
        }
        if (xComputingManager["NetworkInfo"]) {
          for (XMLNode n = xComputingManager["NetworkInfo"]; n; ++n) {
            ComputingManager->NetworkInfo.push_back((std::string)n);
          }
        }
        if (xComputingManager["WorkingAreaShared"]) {
          ComputingManager->WorkingAreaShared = ((std::string)xComputingManager["WorkingAreaShared"] == "true");
        }
        if (xComputingManager["WorkingAreaFree"]) {
          ComputingManager->WorkingAreaFree = stringtoi((std::string)xComputingManager["WorkingAreaFree"]);
        }
        if (xComputingManager["WorkingAreaTotal"]) {
          ComputingManager->WorkingAreaTotal = stringtoi((std::string)xComputingManager["WorkingAreaTotal"]);
        }
        if (xComputingManager["WorkingAreaLifeTime"]) {
          ComputingManager->WorkingAreaLifeTime = (std::string)xComputingManager["WorkingAreaLifeTime"];
        }
        if (xComputingManager["CacheFree"]) {
          ComputingManager->CacheFree = stringtoi((std::string)xComputingManager["CacheFree"]);
        }
        if (xComputingManager["CacheTotal"]) {
          ComputingManager->CacheTotal = stringtoi((std::string)xComputingManager["CacheTotal"]);
        }
        for (XMLNode n = xComputingManager["Benchmark"]; n; ++n) {
          double value;
          if (n["Type"] && n["Value"] &&
              stringto((std::string)n["Value"], value)) {
            (*ComputingManager.Benchmarks)[(std::string)n["Type"]] = value;
          } else {
            logger.msg(VERBOSE, "Couldn't parse benchmark XML:\n%s", (std::string)n);
            continue;
          }
        }
        for (XMLNode n = xComputingManager["ApplicationEnvironments"]["ApplicationEnvironment"]; n; ++n) {
          ApplicationEnvironment ae((std::string)n["AppName"], (std::string)n["AppVersion"]);
          ae.State = (std::string)n["State"];
          if (n["FreeSlots"]) {
            ae.FreeSlots = stringtoi((std::string)n["FreeSlots"]);
          }
          //else {
          //  ae.FreeSlots = ComputingShare->FreeSlots; // Non compatible??, i.e. a ComputingShare is unrelated to the ApplicationEnvironment.
          //}
          if (n["FreeJobs"]) {
            ae.FreeJobs = stringtoi((std::string)n["FreeJobs"]);
          } else {
            ae.FreeJobs = -1;
          }
          if (n["FreeUserSeats"]) {
            ae.FreeUserSeats = stringtoi((std::string)n["FreeUserSeats"]);
          } else {
            ae.FreeUserSeats = -1;
          }
          ComputingManager.ApplicationEnvironments->push_back(ae);
        }

        int eeID = 0;
        for (XMLNode xExecutionEnvironment = xComputingManager["ExecutionEnvironments"]["ExecutionEnvironment"]; (bool)xExecutionEnvironment; ++xExecutionEnvironment) {
          ExecutionEnvironmentType ExecutionEnvironment;
          if (xExecutionEnvironment["Platform"]) {
            ExecutionEnvironment->Platform = (std::string)xExecutionEnvironment["Platform"];
          }

          if (xExecutionEnvironment["MainMemorySize"]) {
            ExecutionEnvironment->MainMemorySize = stringtoi((std::string)xExecutionEnvironment["MainMemorySize"]);
          }

          if (xExecutionEnvironment["OSName"]) {
            if (xExecutionEnvironment["OSVersion"]) {
              if (xExecutionEnvironment["OSFamily"]) {
                ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSFamily"],
                                                                 (std::string)xExecutionEnvironment["OSName"],
                                                                 (std::string)xExecutionEnvironment["OSVersion"]);
              }
              else {
                ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSName"],
                                                                 (std::string)xExecutionEnvironment["OSVersion"]);
              }
            }
            else {
              ExecutionEnvironment->OperatingSystem = Software((std::string)xExecutionEnvironment["OSName"]);
            }
          }

          if (xExecutionEnvironment["ConnectivityIn"]) {
            ExecutionEnvironment->ConnectivityIn = (lower((std::string)xExecutionEnvironment["ConnectivityIn"]) == "true");
          }

          if (xExecutionEnvironment["ConnectivityOut"]) {
            ExecutionEnvironment->ConnectivityOut = (lower((std::string)xExecutionEnvironment["ConnectivityOut"]) == "true");
          }
          ComputingManager.ExecutionEnvironment.insert(std::pair<int, ExecutionEnvironmentType>(eeID++, ExecutionEnvironment));
        }

        cs.ComputingManager.insert(std::pair<int, ComputingManagerType>(managerID++, ComputingManager));
      }

      targets.push_back(cs);
    }
  }