Project

General

Profile

Revision 775d38e1

ID775d38e137bce91984bc8e89d1f28fb00564ea46
Parent 9415e8dd
Child 26cfae1e

Added by Andreas Müller 11 months ago

ref #8469 avoid merge to singular branches

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/generate/PolytomousKeyGenerator.java
309 309

  
310 310
        Map<Set<KeyTaxon>,Boolean> reuseWinner = new HashMap<>();
311 311

  
312
        Set<State> states = getAllStates(winnerFeature, taxaCovered, featureStatesFilter.get(winnerFeature));
312
        Set<State> allStates = getAllStates(winnerFeature, taxaCovered, featureStatesFilter.get(winnerFeature));
313 313
		// a map is created, the key being the set of taxa that present the state(s) stored in the corresponding value
314 314
        // this key represents a single branch in the decision tree
315 315
		Map<Set<KeyTaxon>, List<State>> taxonStatesMap
316
		        = determineCategoricalStates(states, winnerFeature, taxaCovered, featureStatesFilter.get(winnerFeature));
316
		        = determineCategoricalStates(allStates, winnerFeature, taxaCovered, featureStatesFilter.get(winnerFeature));
317 317

  
318 318
		if (taxonStatesMap.size()<=1){
319 319
		    if (notEmpty(featureDependencies.get(winnerFeature))){
......
332 332
		    // if the merge option is ON, branches with the same discriminative power will be merged (see Vignes & Lebbes, 1989)
333 333
		    if (config.isMerge()){
334 334
		        taxonStatesMap = handleMerge(taxaCovered, winnerFeature, reuseWinner,
335
		                taxonStatesMap, featureStatesFilter.get(winnerFeature));
335
		                taxonStatesMap, allStates, featureStatesFilter.get(winnerFeature));
336 336
		    }
337 337
		    List<Set<KeyTaxon>> sortedKeys = sortKeys(taxonStatesMap);
338 338
            for (Set<KeyTaxon> newTaxaCovered : sortedKeys){
......
346 346

  
347 347
    private Map<Set<KeyTaxon>, List<State>> handleMerge(Set<KeyTaxon> taxaCovered,
348 348
            Feature winnerFeature, Map<Set<KeyTaxon>, Boolean> reuseWinner,
349
            Map<Set<KeyTaxon>, List<State>> taxonStatesMap, Set<State> filter) {
349
            Map<Set<KeyTaxon>, List<State>> taxonStatesMap, Set<State> allStates, Set<State> filter) {
350 350

  
351 351
        // creates a map between the different states of the winnerFeature and the sets of states "incompatible" with them
352 352
        Map<State,Set<State>> exclusions = new HashMap<>();
......
355 355
        while (!exclusions.isEmpty()){
356 356
        	// looks for the largest clique, i.e. the state with less exclusions
357 357
        	List<State> clique = returnBestClique(exclusions);
358
        	if(clique.containsAll(allStates)){
359
        	    continue;
360
        	}
358 361
        	// then merges the corresponding branches
359 362
        	mergeBranches(clique, taxonStatesMap, reuseWinner, filter);
360 363
        }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)