如何使此代码对n个项目通用? [英] How to make this code generic for n items?

查看:84
本文介绍了如何使此代码对n个项目通用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我发送一些先验编码...此编码仅用于3个候选世代.如果给出n个项作为输入,该如何编写编码?

here i send some codings for apriori...this coding is used for only 3 candidate generation. if n items is given as a input how to write the coding?

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim i As Integer
        Dim minsup = 20
        Dim minconfid = 40
        Dim mycon As SqlConnection
        Dim mycommand As SqlCommand
        Dim dr As SqlDataReader
        Dim da As New SqlDataAdapter


        Dim q(50) As Integer
        Dim q1(50), bn(50), bn1(50) As Integer

        mycon = New SqlConnection("Data Source=CSESAP04\SQLEXPRESS;Initial Catalog=novel;Integrated Security=True")
        mycon.Open()
        mycommand = New SqlCommand("select * from apriori", mycon)
        '
dr = mycommand.ExecuteReader


        Dim itemcount As Integer = 9


        'for item count....

        For i = 1 To itemcount
            cal1(i)
        Next

        Dim j, h, n As Integer
        Dim m(8) As Integer
        Dim totrans As Integer = 15



        'for single item support

        For j = 0 To ListBox1.Items.Count - 1
            h = (ListBox1.Items(j) / totrans) * 100
            m(j) = h
        Next

        For i = 0 To m.Length - 1
            If m(i) > minsup Then
                ListBox2.Items.Add(i + 1)
            End If
        Next



        'for 2 candidate generation
        Dim v, firstvar, nextvar As Integer
        Dim w As Integer
        Dim h1(50) As Integer
        For v = 0 To ListBox2.Items.Count - 1
            For w = 0 To ListBox2.Items.Count - 1
                firstvar = ListBox2.Items(v)
                nextvar = ListBox2.Items(w)
                ListBox3.Items.Add(firstvar & " ," & nextvar)
                cndsup(firstvar, nextvar)
                'q(v) = firstvar
                'q1(w) = nextvar
                'ListBox3.Items.Add(q(v) & "," & q1(w))
            Next
        Next




        Dim c, t, k, g(100) As Integer
        For c = 0 To ListBox4.Items.Count - 1
            k = (ListBox4.Items(c) / totrans) * 100
            g(c) = k
        Next
        For t = 0 To g.Length - 1
            If g(t) > minsup Then
                'MessageBox.Show("pos is" & t)
                ListBox5.Items.Add(ListBox3.Items(t))
                'tcand(t)
            End If
        Next
        'MessageBox.Show("count is" & ListBox7.Items.Count)


        'for  3 itemset generation

        Dim kf As Integer
        Dim kf1(1000) As Integer
        For kf = 0 To ListBox7.Items.Count - 1
            n = (ListBox7.Items(kf) / totrans) * 100
            kf1(kf) = n
        Next


        For t = 0 To kf1.Length - 1
            If kf1(t) > minsup Then
                'MessageBox.Show("pos is" & t)
                ListBox8.Items.Add(ListBox6.Items(t))
                'tcand(t)
            End If
        Next

    End Sub

推荐答案

我无法阅读该代码,这太可怕了.要执行任意次数的操作,请创建一个可以称为所需次数的循环.
I can'';t read this code, it is horrible. To do anything an arbitrary number of times, create a loop that can be called the number of times required.


这篇关于如何使此代码对n个项目通用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆