Search in sources :

Example 1 with Item

use of nars.entity.Item in project opennars by opennars.

the class BagOperationsTest method testBagSequence.

public static void testBagSequence(Bag b) {
    // different id, different priority
    b.putIn(makeConcept("a", 0.1f));
    b.putIn(makeConcept("b", 0.15f));
    assertEquals(2, b.size());
    b.clear();
    // same priority, different id
    b.putIn(makeConcept("a", 0.1f));
    b.putIn(makeConcept("b", 0.1f));
    assertEquals(2, b.size());
    b.putIn(makeConcept("c", 0.2f));
    assertEquals(2, b.size());
    assertEquals(0.1f, b.getMinPriority(), 0.001f);
    assertEquals(0.2f, b.getMaxPriority(), 0.001f);
    // if (b instanceof GearBag()) return;
    b.putIn(makeConcept("b", 0.4f));
    assertEquals(2, b.size());
    assertEquals(0.2f, b.getMinPriority(), 0.001f);
    assertEquals(0.4f, b.getMaxPriority(), 0.001f);
    Item tb = b.take(new Term("b"));
    assertTrue(tb != null);
    assertEquals(1, b.size());
    assertEquals(0.4f, tb.getPriority(), 0.001f);
    Item tc = b.takeNext();
    assertEquals(0, b.size());
    assertEquals(0.2f, tc.getPriority(), 0.001f);
    assertEquals(null, b.putIn(makeConcept("a", 0.2f)));
    assertEquals(null, b.putIn(makeConcept("b", 0.3f)));
    if (b instanceof LevelBag) {
        // replaces item on level
        assertEquals("a", b.putIn(makeConcept("c", 0.1f)).name().toString());
    }
}
Also used : Item(nars.entity.Item) Term(nars.language.Term) LevelBag(nars.storage.LevelBag)

Example 2 with Item

use of nars.entity.Item in project opennars by opennars.

the class CircleLayout method vertex.

@Override
public void vertex(AbstractGraphVis<Item, Object> g, VertexVis<Item, Object> v) {
    Item vertex = v.getVertex();
    float priority = vertex.getPriority();
    double radius = (1.0 - priority) * spacing + 8;
    boolean task = false;
    Concept x = null;
    if (vertex instanceof Concept) {
        x = (Concept) vertex;
    } else if (vertex instanceof Task) {
        task = true;
        x = nar.memory.concept(((Task) vertex).getTerm());
    }
    float angle = ((arcStop - arcStart) * Video.hashFloat(x.hashCode()) + arcStart) * ((float) Math.PI * 2f);
    v.tx = (float) (Math.cos(angle) * radius) * spacing;
    v.ty = (float) (Math.sin(angle) * radius) * spacing;
    if (task) {
        v.ty += spacing * Video.hashFloat(vertex.hashCode());
    }
}
Also used : Concept(nars.entity.Concept) Item(nars.entity.Item) Task(nars.entity.Task)

Example 3 with Item

use of nars.entity.Item in project opennars by opennars.

the class SpiralLayout method vertex.

@Override
public void vertex(AbstractGraphVis<Item, Object> g, VertexVis<Item, Object> v) {
    Item vertex = v.getVertex();
    float priority = vertex.getPriority();
    boolean task = false;
    Concept x = null;
    if (vertex instanceof Concept) {
        x = (Concept) vertex;
    } else if (vertex instanceof Task) {
        task = true;
        x = nar.memory.concept(((Task) vertex).getTerm());
    }
    int i = 0;
    try {
        for (Concept c : nar.memory.concepts) {
            if (x == c) {
                // not elegant and fast but k at least no term equals
                break;
            }
            i++;
        }
    } catch (Exception ex) {
    }
    float count_elems = nar.memory.concepts.size();
    // float ratio = 30.0f*(0.10f + (((float)priority) / (1.0f)));
    float ratio = 30.0f * (0.10f + (((float) i) / (count_elems)));
    v.tx = (float) (ratio * Math.cos(ratio)) * spacing;
    v.ty = (float) (ratio * Math.sin(ratio)) * spacing;
    if (task) {
        v.ty += spacing * Video.hashFloat(vertex.hashCode());
    }
}
Also used : Concept(nars.entity.Concept) Item(nars.entity.Item) Task(nars.entity.Task)

Example 4 with Item

use of nars.entity.Item in project opennars by opennars.

the class BudgetFunctions method budgetInference.

/**
 * Common processing for all inference step
 *
 * @param qual Quality of the inference
 * @param complexity Syntactic complexity of the conclusion
 * @param nal Reference to the memory
 * @return Budget of the conclusion task
 */
private static BudgetValue budgetInference(final float qual, final float complexity, final nars.control.DerivationContext nal) {
    Item t = nal.getCurrentTaskLink();
    if (t == null) {
        t = nal.getCurrentTask();
    }
    float priority = t.getPriority();
    float durability = t.getDurability() / complexity;
    final float quality = qual / complexity;
    final TermLink bLink = nal.getCurrentBeliefLink();
    if (bLink != null) {
        priority = or(priority, bLink.getPriority());
        durability = and(durability, bLink.getDurability());
        final float targetActivation = conceptActivation(nal.memory, bLink.target);
        bLink.incPriority(or(quality, targetActivation));
        bLink.incDurability(quality);
    }
    return new BudgetValue(priority, durability, quality);
}
Also used : BudgetValue(nars.entity.BudgetValue) Item(nars.entity.Item) TermLink(nars.entity.TermLink)

Aggregations

Item (nars.entity.Item)4 Concept (nars.entity.Concept)2 Task (nars.entity.Task)2 BudgetValue (nars.entity.BudgetValue)1 TermLink (nars.entity.TermLink)1 Term (nars.language.Term)1 LevelBag (nars.storage.LevelBag)1