当前位置:首页>java>让代码代替重复劳动,让AI驱动技术进步

让代码代替重复劳动,让AI驱动技术进步

  • 2026-10-21 13:27:49
让代码代替重复劳动,让AI驱动技术进步
在版图设计中,总线连接是常见但繁琐的任务。如何让数百条平行走线优雅地连接在一起,同时保持布局的美观和电气性能?今天分享AI辅助的解决方案。

背景来源技术群中的讨论:网友木棉有开发分享了这个需求脚本,用45度斜边走线连接连接两组bus代码。 征得同意我尝试porting到Custom Compiler上使用。

初步想法是用AI 直接porting到Tcl 脚本。但是初步porting的效果并不理想,出现如下异常情况。在豆包上多次提示连接异常情况后仍没有优化出想要的效果。但它每次都很自信的告诉我是最终完美版版本。

不纠结让AI 重新写一个这样需求的脚本,主要代码均为AI生成,我手工添加了个简单的GUI 部分代码方便使用。(我的目前的经验是可以先给一些示例比如坐标信息,需要连接的坐标信息等让AI了解最终需求。这样生成的代码往往更接近需求。)

还是让豆包和Deepseek自己帮写出这样的需要。在DeepSeek的上得到了较好的效果,但是语法正确率上没有豆包生成的好。最终两个结合使用。最终得到想要的功能,大约用时1.5小时。

为了快速实现,这里的GUI 界面和使用方式没有过多优化。

Custom Compiler有自带修正offgrid的功能,当然脚本中也可以带上自带修正格点的function.

欢迎关注我的公众号,获取更多IC设计自动化技巧和工具分享。如果你有特定的设计挑战,也欢迎留言讨论!

#!/usr/bin/tclsh# =============================================================# 功能:水平/竖直平行BUS总线 顺序一对一45°斜线连接# 适配场景:A/B组均为平行线、严格顺序配对、无交叉无重叠、45°等宽斜线# 输入格式:每组走线 = {{{x1 y1} {x2 y2}} {{x1 y1} {x2 y2}} ...}# 核心保证:① 顺序不变 ② 纯45°斜线(|Δx|=|Δy|) ③ 无重叠交叉 ④ 连线最短# =============================================================proc connect_bus_45 {busA busB} {    set connect_all [list]    set pair_num [llength $busA]    if {[llength $busA] != [llength $busB]} {        puts "Warning: BUS A count=[llength $busA], BUS B count=[llength $busB], only connect min pair"        set pair_num [expr {min([llength $busA],[llength $busB])}]    }    for {set i 0} {$i < $pair_num} {incr i} {        set segA [lindex $busA $i]        set segB [lindex $busB $i]        lassign $segA a1 a2        lassign $segB b1 b2        # Auto detect HORIZONTAL / VERTICAL        lassign $a1 ax1 ay1        lassign $a2 ax2 ay2        lassign $b1 bx1 by1        lassign $b2 bx2 by2        set dirA [expr {$ax1 == $ax2 ? "vertical" : "horizontal"}]        set dirB [expr {$bx1 == $bx2 ? "vertical" : "horizontal"}]        # 如果两条线段方向不一致,默认按照dirA处理        if {$dirA ne $dirB} {            puts "Warning: Segment directions differ at pair $i (A:$dirA, B:$dirB), using A's direction"        }        # ========== ✅ 优化核心算法:真正找到最近端点 ==========        if {$dirA eq "vertical"} {            # 垂直线段:计算所有端点对的距离,选择最近的            set a_top [list $ax1 [expr {max($ay1,$ay2)}]]            set a_bot [list $ax1 [expr {min($ay1,$ay2)}]]            set b_top [list $bx1 [expr {max($by1,$by2)}]]            set b_bot [list $bx1 [expr {min($by1,$by2)}]]            # 计算所有可能端点对的距离(使用欧几里得距离公式)            set pairs [list]            set dx [expr {$ax1 - $bx1}]            set dy_top_top [expr {[lindex $a_top 1] - [lindex $b_top 1]}]            set dy_top_bot [expr {[lindex $a_top 1] - [lindex $b_bot 1]}]            set dy_bot_top [expr {[lindex $a_bot 1] - [lindex $b_top 1]}]            set dy_bot_bot [expr {[lindex $a_bot 1] - [lindex $b_bot 1]}]            lappend pairs [list $a_top $b_top [expr {sqrt($dx*$dx + $dy_top_top*$dy_top_top)}]]            lappend pairs [list $a_top $b_bot [expr {sqrt($dx*$dx + $dy_top_bot*$dy_top_bot)}]]            lappend pairs [list $a_bot $b_top [expr {sqrt($dx*$dx + $dy_bot_top*$dy_bot_top)}]]            lappend pairs [list $a_bot $b_bot [expr {sqrt($dx*$dx + $dy_bot_bot*$dy_bot_bot)}]]            # 按距离排序,取最近的            set pairs [lsort -real -index 2 $pairs]            lassign [lindex $pairs 0] a_link b_link dist        } else {            # 水平线段:计算所有端点对的距离,选择最近的            set a_right [list [expr {max($ax1,$ax2)}] $ay1]            set a_left  [list [expr {min($ax1,$ax2)}] $ay1]            set b_right [list [expr {max($bx1,$bx2)}] $by1]            set b_left  [list [expr {min($bx1,$bx2)}] $by1]            # 计算所有可能端点对的距离            set pairs [list]            set dy [expr {$ay1 - $by1}]            set dx_right_right [expr {[lindex $a_right 0] - [lindex $b_right 0]}]            set dx_right_left  [expr {[lindex $a_right 0] - [lindex $b_left 0]}]            set dx_left_right  [expr {[lindex $a_left 0] - [lindex $b_right 0]}]            set dx_left_left   [expr {[lindex $a_left 0] - [lindex $b_left 0]}]            lappend pairs [list $a_right $b_right [expr {sqrt($dx_right_right*$dx_right_right + $dy*$dy)}]]            lappend pairs [list $a_right $b_left  [expr {sqrt($dx_right_left*$dx_right_left + $dy*$dy)}]]            lappend pairs [list $a_left  $b_right [expr {sqrt($dx_left_right*$dx_left_right + $dy*$dy)}]]            lappend pairs [list $a_left  $b_left  [expr {sqrt($dx_left_left*$dx_left_left + $dy*$dy)}]]            # 按距离排序,取最近的            set pairs [lsort -real -index 2 $pairs]            lassign [lindex $pairs 0] a_link b_link dist        }        lassign $a_link ax ay        lassign $b_link bx by        # ========== ✅ 45°斜线核心公式:确保|Δx|=|Δy| ==========        set dx [expr {abs($bx-$ax)}]        set dy [expr {abs($by-$ay)}]        set delta [expr {min($dx, $dy)}]        # 计算45度线的终点(从a_link出发)        set s_x [expr {$ax + ($bx > $ax ? $delta : -$delta)}]        set s_y [expr {$ay + ($by > $ay ? $delta : -$delta)}]        set slope_start $a_link        set slope_end   [list $s_x $s_y]        lappend connect_all [list "bus_pair_$i" $segA $segB $slope_start $slope_end $a_link $b_link]    }    return $connect_all}proc print_bus_connect {connect_data} {    global AbusArray    foreach pair $connect_data {        lassign $pair idx segA segB s_start s_end a_link b_link        lassign $segA a1 a2        lassign $segB b1 b2        # ✅ 确定a_other(不是a_link的那个端点)        if {[lindex $a1 0]==[lindex $a_link 0] && [lindex $a1 1]==[lindex $a_link 1]} {            set a_other $a2        } else {            set a_other $a1        }        # ✅ 确定b_other(不是b_link的那个端点)        if {[lindex $b1 0]==[lindex $b_link 0] && [lindex $b1 1]==[lindex $b_link 1]} {            set b_other $b2        } else {            set b_other $b1        }        # ✅ 生成正确的连接顺序:a_other -> a_link -> 45°线 -> b_link -> b_other        set full_line [list $a_other $a_link $s_end $b_link $b_other]        # ✅ 去重,避免重复点        set clean_line [list]        foreach p $full_line {            if {[lsearch -exact $clean_line $p] == -1} {                lappend clean_line $p            }        }        if {[info exists AbusArray($segA)]} {            set layerName [lindex $AbusArray($segA) 0]            set width [lindex $AbusArray($segA) end]            # 创建路径            le::createPath [po::compress $clean_line] -design [ed] -lpp $layerName -width $width        }        # 简洁日志        lassign $s_start x1 y1        lassign $s_end x2 y2        puts "Pair $idx: A_link=$a_link, B_link=$b_link, 45°_link $s_start <-> $s_end, dx=[expr {abs($x2-$x1)}], dy=[expr {abs($y2-$y1)}], 45=[expr {abs($x2-$x1)==abs($y2-$y1)}]"    }}# =============================================================# GUI和选择功能保持不变# =============================================================proc selectAbus {widget} {    global busA AbusArray    set busA {}    catch {array unset AbusArray}    array set AbusArray [list]    set busASelected [de::getSelected -design [ed]]    db::foreach eachSegA $busASelected {        if {[db::getAttr objType -of $eachSegA] == "Path" || [db::getAttr objType -of $eachSegA] == "PathSeg"} {            set layerName [db::getAttr object.LPP.lpp -of $eachSegA]            set pathWidth [db::getAttr object.width -of $eachSegA]            set pathPoints [db::getAttr object.points -of $eachSegA]            lappend busA $pathPoints            set AbusArray($pathPoints) [list $layerName $pathWidth]        }    }    puts "Selected [llength $busA] segments for Bus A"}proc selectBbus {widget} {    global busB BbusArray    set busB {}    catch {array unset BbusArray}    array set BbusArray [list]    set busBSelected [de::getSelected -design [ed]]    db::foreach eachSegB $busBSelected {        if {[db::getAttr objType -of $eachSegB] == "Path" || [db::getAttr objType -of $eachSegB] == "PathSeg"} {            set layerName [db::getAttr object.LPP.lpp -of $eachSegB]            set pathWidth [db::getAttr object.width -of $eachSegB]            set pathPoints [db::getAttr object.points -of $eachSegB]            lappend busB $pathPoints            set BbusArray($pathPoints) [list $layerName $pathWidth]        }    }    puts "Selected [llength $busB] segments for Bus B"}proc connectBus {widget} {    global busA busB    if {[llength $busA] == 0 || [llength $busB] == 0} {        puts "Error: Please select both Bus A and Bus B first"        return    }    set result [connect_bus_45 $busA $busB]    print_bus_connect $result}# =============================================================# 创建GUI界面# =============================================================catch {db::destroy [gi::getDialogs testDialog]}set dialog [gi::createDialog testDialog -title "BUS Connection Tool" -execProc connectBus]gi::createPushButton btnAName -parent $dialog -label "Select First Bus (A)" -execProc selectAbus gi::createPushButton btnBName -parent $dialog -label "Select Second Bus (B)" -execProc selectBbus gi::createPushButton btnCName -parent $dialog -label "Connect Bus A and Bus B" -execProc connectBus gi::setDialogSize $dialog -width 300 -height 150

最新文章

随机文章