Search in sources :

Example 1 with UnParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.UnParameterization in project elki by elki-project.

the class DocumentParameters method buildParameterIndex.

private static void buildParameterIndex(Map<Class<?>, List<Parameter<?>>> byclass, Map<OptionID, List<Pair<Parameter<?>, Class<?>>>> byopt) {
    final ArrayList<TrackedParameter> options = new ArrayList<>();
    ExecutorService es = Executors.newSingleThreadExecutor();
    List<Class<?>> objs = ELKIServiceRegistry.findAllImplementations(Object.class, false, true);
    Collections.sort(objs, new ELKIServiceScanner.ClassSorter());
    Class<?> appc = appBaseClass();
    for (final Class<?> cls : objs) {
        // Doesn't have a proper name?
        if (cls.getCanonicalName() == null) {
            continue;
        }
        // constructors / parameterizers and may start AWT threads - skip them.
        if (appc != null && appc.isAssignableFrom(cls)) {
            continue;
        }
        UnParameterization config = new UnParameterization();
        TrackParameters track = new TrackParameters(config, cls);
        try {
            // Wait up to one second.
            es.submit(new // 
            FutureTask<Object>(new Instancer(cls, track, options), // 
            null)).get(1L, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            LOG.warning("Timeout on instantiating " + cls.getName());
            es.shutdownNow();
            throw new RuntimeException(e);
        } catch (Exception e) {
            LOG.warning("Error instantiating " + cls.getName(), e.getCause());
            continue;
        }
    }
    LOG.debug("Documenting " + options.size() + " parameter instances.");
    for (TrackedParameter pp : options) {
        if (pp.getOwner() == null || pp.getParameter() == null) {
            LOG.debugFiner("Null: " + pp.getOwner() + " " + pp.getParameter());
            continue;
        }
        Class<?> c = (Class<?>) ((pp.getOwner() instanceof Class) ? pp.getOwner() : pp.getOwner().getClass());
        Parameter<?> o = pp.getParameter();
        // just collect unique occurrences
        {
            List<Parameter<?>> byc = byclass.get(c);
            boolean inlist = false;
            if (byc != null) {
                for (Parameter<?> par : byc) {
                    if (par.getOptionID() == o.getOptionID()) {
                        inlist = true;
                        break;
                    }
                }
            }
            if (!inlist) {
                List<Parameter<?>> ex = byclass.get(c);
                if (ex == null) {
                    byclass.put(c, ex = new ArrayList<>());
                }
                ex.add(o);
            }
        }
        {
            List<Pair<Parameter<?>, Class<?>>> byo = byopt.get(o.getOptionID());
            boolean inlist = false;
            if (byo != null) {
                for (Pair<Parameter<?>, Class<?>> pair : byo) {
                    if (pair.second.equals(c)) {
                        inlist = true;
                        break;
                    }
                }
            }
            if (!inlist) {
                List<Pair<Parameter<?>, Class<?>>> ex = byopt.get(o.getOptionID());
                if (ex == null) {
                    byopt.put(o.getOptionID(), ex = new ArrayList<>());
                }
                ex.add(new Pair<Parameter<?>, Class<?>>(o, c));
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TrackParameters(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackParameters) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UnParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.UnParameterization) FutureTask(java.util.concurrent.FutureTask) ELKIServiceScanner(de.lmu.ifi.dbs.elki.utilities.ELKIServiceScanner) ExecutorService(java.util.concurrent.ExecutorService) RandomParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.RandomParameter) ClassParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter) Parameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter) ClassListParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassListParameter) TrackedParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter) ArrayList(java.util.ArrayList) List(java.util.List) TrackedParameter(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter) TimeoutException(java.util.concurrent.TimeoutException) Pair(de.lmu.ifi.dbs.elki.utilities.pairs.Pair)

Aggregations

ELKIServiceScanner (de.lmu.ifi.dbs.elki.utilities.ELKIServiceScanner)1 TrackParameters (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackParameters)1 TrackedParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter)1 UnParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.UnParameterization)1 ClassListParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassListParameter)1 ClassParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ClassParameter)1 Parameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter)1 RandomParameter (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.RandomParameter)1 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 FutureTask (java.util.concurrent.FutureTask)1 TimeoutException (java.util.concurrent.TimeoutException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1