Backtrack in a Generic list

96 views Asked by At

I want to create a backtrack that select's me the best value of tasks in my generic list. This is how my generic list looks.

I have a method that sorts my list by the price. I have 3 type of "task" Urgent,Return and Normal. I fill my list up that my Urgent tasks as first (sorted by the price) then return tasks and then normal. And i want the highest value of price in 8 hours but I need to finish urgent first and then return tasks if I still have time and last the normal tasks.

class GenerikusLancoltLista<T> : IEnumerable
{
    class ListaElem
    {
        public T data;
        public ListElement next;
    }
        
    ListaElem Head;
    public GenerikusLancoltLista()
    {
        Head = null;
    }

public void PrioritasiSorBeszuras(T paste)
{
    ListElement new = new ListElement();
    uj.data = paste;
    if (Head == null)
    { Head = new; }
    else
    {
        if ((Head.data as IComparable).CompareTo(paste) >= 0)
        {
            new.next = Head;
            Head = new;
        }
        else
        {
            ListElement p = Head;
            ListElement e = null;
            while (p != null && (p.data as IComparable).CompareTo(paste) < 0)
            {
                e = p;
                p = p.next;
            }
            if (p == null)
            { e.next = new; }
            else
            {
                new.next = p;
                e.next = new;
            }
        }
    }
}

My base task looks like this

interface ITask:IComparable
{
    string Name { get; }
    int price { get; }
    int hour { get; }
    int Priority { get; }
}

So I know bactrack should look something like this. But I dont know how to figure it out a solution that works.

abstract class BacktrackBase
{
    int N;
    GenerikusLancoltLista<ITask> R;
    int[] M;
    public BacktrackBase(int n, GenerikusLancoltLista<ITask> r, int[] m)
    {
        N = n;
        R = r;
        M = m;
    }
    protected abstract bool Ft(int level, ITask task);
    protected abstract bool Fk(int level, ITask task, ITask[] E);

    void Backtrack(int level,Task[] E, ref bool have)
    {
        int i = -1;
        while (!have && i <M[level] - 1)
        {
            i++;
            if (Ft(level, R[level, i]))
            {
                if (Fk(level, R[level, i], E))
                {
                    E[level] = R[level, i];
                    if (level == N - 1)
                    {
                        have = true;
                    }
                    else
                    {
                        Backtrack(level + 1, E, ref have);
                    }
                }
            }
        }
    }

I want to fill my 8 hours with works with the best value for example a work looks like this: Dog walking,10000,3 so "name","price","time"

Each work has a type, "urgent","return","normal".

I need to fit urgent works first with in my 8 hours with the best value.

0

There are 0 answers