コード例 #1
0
ファイル: sll.c プロジェクト: rachelcarandang/funtimes
/* mergeAndOrder inserts each item of list1, in order, into 
"list", starting with list=NULL. The function ensures that the 
second argument of insertOrder is always an ordered list, according 
to the contract of insertOrder. Then it inserts each item of list2. */
SLL *SLL_mergeAndOrder(SLL * list1, SLL * list2) {
	SLL *p, *temp, *list=NULL;
	for (p=list1; p!=NULL; p= temp) {
		temp= p->next;
		list= insertOrder(p, list);
		}
	for (p=list2; p!=NULL; p=temp) {
		temp=p->next;
		list= insertOrder(p, list);
		p= temp;
		}
	return list;
}
コード例 #2
0
ファイル: userform.cpp プロジェクト: itumashyk/TofP
void UserForm::on_orderButton_clicked()
{
    int selectedRow = ui->tableView->currentIndex().row();
    if (selectedRow >= 0)
    {
        QString name = productsModel->index(selectedRow, Name).data().toString();
        QString price = productsModel->index(selectedRow,Price).data().toString();
        int id = productsModel->index(selectedRow, 0).data().toInt();

        bool ok;
        QString label = "You are going to by " + name + " for " + price +
            "$. " + "Please, inser address to deliver:";
        QString adress = QInputDialog::getText(this, "Order Product", label,
                                               QLineEdit::Normal, "", &ok);
        if (ok) {
            insertOrder(id, adress);
        }

    }
    else
    {
        QMessageBox::warning(this, "Make Order",
            "Please, select product first");
    }
}
コード例 #3
0
ファイル: binary_tree.cpp プロジェクト: ashvant/Algorithms-1
bool insertOrder(Tree &T, int data)
{
	if (T == NULL)
	{
		T = new TreeNode;
		T->data = data;
		T->left = T->right = NULL;
		return true;
	}
	else if (data < T->data)
	{
		return insertOrder(T->left, data);
	}
	else if (data > T->data)
	{
		return insertOrder(T->right, data);
	}
	else
		return false;
}
コード例 #4
0
ファイル: VRP_Solver.cpp プロジェクト: titanofold/pgrouting
void CVRPSolver::insertUnservedOrders(CSolutionInfo& curSolution) {
    ++m_iGeneratedSolutionCount;
    ++m_iStepsSinceLastSolution;
    bool insertAvailable = true;
    CMoveInfo curMove;
    int totalUnservedOrder = static_cast<int>(m_vOrderInfos.size() - curSolution.getOrderServed());

    while (insertAvailable &&  totalUnservedOrder > 0) {
        int insertTourId = -1;
        insertAvailable = false;
        int totalTour = static_cast<int>(curSolution.getTourInfoVector().size());
        std::pair<int, int> PotentialInsert;  //  first = insert_index, second = removed_customer_index;
        std::pair<int, double> bestInsert = std::make_pair(-1, DOUBLE_MAX);  // first = customer_insert_index, second = cost;

        for (int j = 0; j < totalTour; ++j) {
            CTourInfo curTour = curSolution.getTour(j);
            curMove.setInitialTour(curTour);

            for (int i = 0; i < totalUnservedOrder; ++i) {
                int ordIndex = m_mapOrderIdToIndex[curSolution.getUnservedOrderAt(i)];
                COrderInfo curOrder = m_vOrderInfos[ordIndex];
                std::pair<int, double> curInsert = getPotentialInsert(curTour, curOrder);

                insertOrder(curTour, i, curInsert.first);
                curMove.setModifiedTour(curTour);
                curMove.getInitialTour(curTour);

                // check if current move is tabu.
                if (isTabuMove(curMove)) {
                    continue;
                }

                if (curInsert.second < bestInsert.second) {
                    insertTourId = j;
                    insertAvailable = true;
                    bestInsert = curInsert;
                    PotentialInsert = std::make_pair(curInsert.first, i);
                }
            }
        }
        if (insertAvailable) {
            totalUnservedOrder--;
            curMove.setInitialTour(curSolution.getTour(insertTourId));

            addOrderAtTour(curSolution, insertTourId,
                    PotentialInsert.first,
                    PotentialInsert.second);

            curMove.setModifiedTour(curSolution.getTour(insertTourId));
            this->updateTabuCount(curMove);
            this->updateFinalSolution(curSolution);  // this->evaluateCurrentSolution();
        }
    }
}
コード例 #5
0
ファイル: b.c プロジェクト: rachelcarandang/funtimes
SLL *SLL_mergeAndOrder(SLL * list1, SLL * list2) {
	SLL *p1, *p2, *newList=NULL;
	for (p1=list1, p2=list2;
		p1 != NULL && p2 != NULL;
		p1= p1->next, p2= p2->next) {
		printf("p1 at this point=%s\n", p1->s);
		printf("p2 at this point=%s\n", p2->s);
		newList= insertOrder(p1->s, newList);
		newList= insertOrder(p2->s, newList);
	}
	if ((p1==NULL) && (p2!=NULL)) {
		for (; p2!=NULL; p2=p2->next) {
		newList= insertOrder(p2->s, newList);
		}
	}
	if ((p1!=NULL) && (p2==NULL)) {
		for (; p1!=NULL; p1=p1->next) {
		newList= insertOrder(p1->s, newList);
		}
	}
	return newList;
}
コード例 #6
0
ファイル: binary_tree.cpp プロジェクト: ashvant/Algorithms-1
int main()
{
	Tree T = NULL;
	for (int i = 0; i < 10; i++)
	{
		insertOrder(T, i);
	}

	std::cout << std::endl;

    mid_order(T);
	std::cout << std::endl;


    delete_tree(T, 5);


    mid_order(T);
	std::cout << std::endl;

	return 0;
}
コード例 #7
0
ファイル: prg6_4.cpp プロジェクト: MCDELTAT/CSE330
int main()
{
	// object read as an entry from the files
	graduate grad;
	
	// list holds graduates in two sections "BS" and "BA"
	list<graduate> gradBA_list, gradBS_list, diplomalist;


	// streams to input registrar's list and dean's list
	ifstream gradIn, noAttIn;

	// open registrar's list file
	gradIn.open("gradlist.dat");
	if (!gradIn)
	{
		cerr << "Cannot open file 'gradlist.dat'" << endl;
		exit(1);
	}

	// read registrar's list to end-of-file and add to list
	while(true)
	{
		gradIn >> grad;
		if (!gradIn)
			break;
		if(grad.getDegree() == "BS")
			insertOrder(gradBS_list, grad);
		else
			insertOrder(gradBA_list, grad);
	}

  	gradIn.close();

	// open file of those not attending graduation
	noAttIn.open("noattend.dat");
	if (!noAttIn)
	{
		cerr << "Cannot open file 'noattend.dat'" << endl;
		exit(1);
	}
		
	// read list of those not attending to end-of-file and
	// remove each graduate from the list
	while(true)
	{
		noAttIn >> grad;
		if (!noAttIn)
			break;
		if (grad.getDegree() == "BS")
			removeGraduate(gradBS_list,grad);
		else
			removeGraduate(gradBA_list, grad);
	}

	diplomalist = gradBS_list;
	splice<graduate>(diplomalist, diplomalist.end(), gradBA_list);
  	
	// output list of graduates at ceremony by sections. use
	// a newline separator between names
	cout << "Students at Graduation" << endl << endl;
  	writeList(diplomalist, "\n");

	return 0;
}
コード例 #8
0
ファイル: VRP_Solver.cpp プロジェクト: titanofold/pgrouting
bool CVRPSolver::addOrderAtTour(CSolutionInfo &solutionInfo, int tourIndex, int insertIndex, int orderIndex) {
    return(insertOrder(solutionInfo.getTour(tourIndex), m_vOrderInfos[orderIndex].getOrderId(), insertIndex));
}
コード例 #9
0
ファイル: VRP_Solver.cpp プロジェクト: titanofold/pgrouting
CSolutionInfo CVRPSolver::generateInitialSolution() {
    CSolutionInfo initialSolution;
    PGR_LOG("Inside gen ini sol");
    std::vector<int> vecOrders, vecVehicles;
    for (unsigned int i = 0; i < m_vOrderInfos.size(); i++) {
        vecOrders.push_back(m_vOrderInfos[i].getOrderId());
    }

    for (unsigned int i = 0; i < m_vVehicleInfos.size(); i++) {
        vecVehicles.push_back(m_vVehicleInfos[i].getId());
    }

    initialSolution.init(vecOrders, static_cast<int>(vecOrders.size()), vecVehicles);

    int iUnusedVehicles = static_cast<int>(initialSolution.getUnusedVehicleCount());
    int iUnservedOrders = static_cast<int>(initialSolution.getUnservedOrderCount());  // m_viUnservedOrderIndex.size();
    PGR_LOG("before while");
    while (iUnusedVehicles &&  iUnservedOrders) {
        CTourInfo curTour;

        int vehicleIndex = rand() % iUnusedVehicles--;
        int vehicleInd = m_mapVehicleIdToIndex[initialSolution.getUnusedVehicleAt(vehicleIndex)];
        curTour.setVehicleInfo(m_vVehicleInfos[vehicleInd]);  // m_viUnusedVehicleIndex[vehicleIndex]
        initialSolution.removeVehicle(vehicleIndex);

        curTour.setStartDepot(m_vDepotInfos[0].getDepotId());
        curTour.setEndDepot(m_vDepotInfos[0].getDepotId());

        // use a random seed to start to tour. (we can use better approach in future)

        bool insertAvailable = true;

        while (insertAvailable) {
            insertAvailable = false;
            std::pair<int, int> PotentialInsert;  //  first = insert_index, second = removed_order_index;
            std::pair<int, double> bestInsert = std::make_pair(-1, DOUBLE_MAX);  // first = order_insert_index, second = cost;

            for (int i = 0; i < iUnservedOrders; ++i) {
                int orderInd = m_mapOrderIdToIndex[initialSolution.getUnservedOrderAt(i)];
                COrderInfo curOrder = m_vOrderInfos[orderInd];
                std::pair<int, double> curInsert = getPotentialInsert(curTour, curOrder);

                if (curInsert.second < bestInsert.second) {
                    insertAvailable = true;
                    bestInsert = curInsert;
                    PotentialInsert = std::make_pair(curInsert.first, i);
                }
            }
            if (insertAvailable) {
                if (insertOrder(curTour, initialSolution.getUnservedOrderAt(PotentialInsert.second), PotentialInsert.first)) {
                    iUnservedOrders--;
                    initialSolution.removeOrder(PotentialInsert.second);
                }
            }
        }

        initialSolution.addTour(curTour);
    }

    return initialSolution;
}